Calendar

August 2008
S M T W T F S
« Jul   Sep »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Tag Cloud

Categories

Archives

Recent Posts

Recent Comments


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

Get IPAddress into Flash

By Rich Tretola | August 7, 2008
5,811 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
3
4
5
<head>
<%
String flashIPAddress=request.getRemoteAddr();
%>
</head>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<%
String flashIPAddress=request.getRemoteAddr();
%>
<script src="AC_OETags.js" language="javascript"></script>
</head>

<body scroll='no'>
<script language="JavaScript" type="text/javascript">
<!--
        AC_FL_RunContent(
                    "src", "temp",
                    "width", "100%",
                    "height", "100%",
                    "align", "middle",
                    "id", "temp",
                    "quality", "high",
                    "bgcolor", "#869ca7",
                    "name", "test",
                                       "flashvars","flashIPAddress=<%= flashIPAddress %>",
                    "allowScriptAccess","sameDomain",
                    "type", "application/x-shockwave-flash",
                    "pluginspage", "http://www.adobe.com/go/getflashplayer"
    );
// -->
</script>
<noscript>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            id="temp" width="100%" height="100%"
            codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
            <param name="movie" value="test.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#869ca7" />
            <param name="allowScriptAccess" value="sameDomain" />
                        <param name="flashvars"value="flashIPAddress=<%= flashIPAddress %>"/>
            <embed src="test.swf" quality="high" bgcolor="#869ca7"
                width="100%" height="100%" name="temp" align="middle"
                play="true"
                loop="false"
                quality="high"
                allowScriptAccess="sameDomain"
                               flashVars="flashIPAddress=<%= flashIPAddress %>"
                type="application/x-shockwave-flash"
                pluginspage="http://www.adobe.com/go/getflashplayer">
            </embed>
    </object>
</noscript>
</body>
</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/Bookmark

Topics: Flex | 4 Comments »

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

    PHP CODE:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
     $REMOTE_ADDR;
    if ($REMOTE_ADDR)
    {
        $message =  "<result><ip>$REMOTE_ADDR</ip></result>";
    }
    else
    {
        $message = "<result><ip>No Ip or any message.</ip></result>";
    }
    echo $message;
    ?>

    Reply to this comment

  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.

    Reply to this comment

  3. Tom Says:
    December 18th, 2008 at 5:36 pm

    Is it a joke?

    Reply to this comment

  4. Websites tagged "read" on Postsaver Says:
    June 17th, 2009 at 6:32 am

    [...] – Get IPAddress into Flash saved by potato7942009-06-07 – Return to Death Race saved by thecdude2009-06-03 – US Jr dragster [...]

Comments