Calendar

August 2008
M T W T F S S
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

Tag Cloud

Categories

Archives

Highest Rated

Most Viewed

Recent Posts

Recent Comments


« Congrats to Open Flex! | Main | Win free AIR Books »

Get IPAddress into Flash

By Rich Tretola | August 7, 2008Print This Post Print This Post
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4 out of 5)
Loading ... Loading ...
1,989 views

I have had a few people ask how to read the users IPAddress from within Flash. The way I do this is to use my application server to write the IPAddress into a flash var which I then read from flash. This is obviously open to spoofing if the user wants to play games as the IPAddress is displayed within the page source however it fulfills my needs.

For example my Index.jsp looks something like this:

  1. <%
  2. String flashIPAddress=request.getRemoteAddr();
  3. %>
  4. </head>
  1. <html lang="en">
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  3. <title></title>
  4. <%
  5. String flashIPAddress=request.getRemoteAddr();
  6. %>
  7. <script src="AC_OETags.js" language="javascript"></script>
  8. </head>
  9.  
  10. <body scroll='no'>
  11. <script language="JavaScript" type="text/javascript">
  12. <!--
  13.         AC_FL_RunContent(
  14.                     "src", "temp",
  15.                     "width", "100%",
  16.                     "height", "100%",
  17.                     "align", "middle",
  18.                     "id", "temp",
  19.                     "quality", "high",
  20.                     "bgcolor", "#869ca7",
  21.                     "name", "test",
  22.                                         "flashvars","flashIPAddress=<%= flashIPAddress %>
  23. ",
  24.                     "allowScriptAccess","sameDomain",
  25.                     "type", "application/x-shockwave-flash",
  26.                     "pluginspage", "http://www.adobe.com/go/getflashplayer"
  27.     );
  28. // -->
  29. </script>
  30.     <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  31.             id="temp" width="100%" height="100%"
  32.             codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
  33.             <param name="movie" value="test.swf" />
  34.             <param name="quality" value="high" />
  35.             <param name="bgcolor" value="#869ca7" />
  36.             <param name="allowScriptAccess" value="sameDomain" />
  37.                         <param name="flashvars"value="flashIPAddress=<%= flashIPAddress %>"/>
  38.             <embed src="test.swf" quality="high" bgcolor="#869ca7"
  39.                 width="100%" height="100%" name="temp" align="middle"
  40.                 play="true"
  41.                 loop="false"
  42.                 quality="high"
  43.                 allowScriptAccess="sameDomain"
  44.                                 flashVars="flashIPAddress=<%= flashIPAddress %>"
  45.                 type="application/x-shockwave-flash"
  46.                 pluginspage="http://www.adobe.com/go/getflashplayer">
  47.             </embed>
  48.     </object>
  49. </noscript>
  50. </body>
  51. </html>

Notice that I grab the IPAddress in the head and then pass it in 3 different places within the flash embed and script code:

Now within my application I simply refer to this var like this:

  1. var ipAddress:String = Application.application.parameters.flashIPAddress;

You could certainly take the same approach within a ColdFusion, ASP, or PHP environment as well.

Share/Save/Bookmark

Topics: Flex |

2 Responses to “Get IPAddress into Flash”

  1. mnieves Says:
    August 10th, 2008 at 9:39 pm

    hello here is a php code and a flex example.

    MXML CODE:

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    3. <mx:HTTPService id="dir" url="http://yourdomain.com/ip.php" resultFormat="e4x" />
    4.     <mx:Button  label="Get IP" click="dir.send()" x="258" y="238"/>
    5.     <mx:TextInput  text="Ip:{dir.lastResult.ip}" x="210" y="208"/>
    6. </mx:Application>

    PHP CODE:

    1. <?php
    2.  $REMOTE_ADDR;
    3. if ($REMOTE_ADDR)
    4. {
    5.     $message"<result><ip>$REMOTE_ADDR</ip></result>";
    6. }
    7. else
    8. {
    9.     $message = "<result><ip>No Ip or any message.</ip></result>";
    10. }
    11. echo $message;
    12. ?>
  2. wodesign Says:
    August 14th, 2008 at 9:24 pm

    so,first way is good if off line;and if the client on line,the seconed is better.

Comments