calculating client IP address

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lowell Kirsh

    #1

    calculating client IP address

    I want to create a link that a user can click which will create a popup
    telling the user their ip address. I have:

    var ip = new java.net.InetAd dress.getLocalH ost().toString( );
    alert("Your IP address is: " + ip.substring(ip .indexOf("/")+1))

    but this does not seem to work. It says the ip is 127.0.0.1. Strangely,
    this piece of code used to work but all of a sudden it doesn't for some
    unknown reason. Can anyone tell me what's wrong with the above code?

    Lowell
  • Evertjan.

    #2
    Re: calculating client IP address

    Lowell Kirsh wrote on 21 aug 2004 in comp.lang.javas cript:[color=blue]
    > I want to create a link that a user can click which will create a popup
    > telling the user their ip address. I have:[/color]

    If it does not direct to a[nother] page it is not a link
    [color=blue]
    > var ip = new java.net.InetAd dress.getLocalH ost().toString( );
    > alert("Your IP address is: " + ip.substring(ip .indexOf("/")+1))[/color]

    What scriptlanguage/platform are you using ["new java.net"?]?
    Surely not clientside javascript with DOM [=wisdom?] ?
    [color=blue]
    > but this does not seem to work. It says the ip is 127.0.0.1. Strangely,
    > this piece of code used to work but all of a sudden it doesn't for some
    > unknown reason. Can anyone tell me what's wrong with the above code?[/color]

    We would first have to know the above.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Michael Winter

      #3
      Re: calculating client IP address

      On 21 Aug 2004 07:41:23 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
      wrote:
      [color=blue]
      > Lowell Kirsh wrote on 21 aug 2004 in comp.lang.javas cript:[/color]

      [snip]
      [color=blue][color=green]
      >> var ip = new java.net.InetAd dress.getLocalH ost().toString( );
      >> alert("Your IP address is: " + ip.substring(ip .indexOf("/")+1))[/color]
      >
      > What scriptlanguage/platform are you using ["new java.net"?]?
      > Surely not clientside javascript with DOM [=wisdom?] ?[/color]

      It's Java (the networking package) being called from JavaScript. Opera and
      IE don't seem to support that (if they do, a different syntax is required).
      [color=blue][color=green]
      >> but this does not seem to work. It says the ip is 127.0.0.1. Strangely,
      >> this piece of code used to work but all of a sudden it doesn't for some
      >> unknown reason. Can anyone tell me what's wrong with the above code?[/color][/color]

      Whilst this would be more appropriate in a Java group, you're here now.

      If you look at the description of the getLocalHost() method, you'll see:

      If there is a security manager, its checkConnect method is called
      with the local host name and -1 as its arguments to see if the
      operation is allowed. If the operation is not allowed, an
      InetAddress representing the loopback address is returned.

      Java running under JavaScript will be using a security manager and, I
      should imagine, a very restricted one at that. Whilst the code worked
      running on my machine (using only Mozilla and Netscape, I might add), I
      doubt that it will work from a remote host. In that case, as it states
      above, you'll have the loopback address returned.

      In other words: it a security thing that you can do nothing about.

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Andrew Thompson

        #4
        Re: calculating client IP address

        On Sat, 21 Aug 2004 08:14:10 GMT, Michael Winter wrote:
        [color=blue]
        > Java running under JavaScript will be using a security manager and, I
        > should imagine, a very restricted one at that.[/color]

        Java run under the control of JS is actually subjected
        to a more strict security environment than are regular
        applets. Im afraid I have few further details, but am
        amazed the OP could ever get any access to the user's IP
        address using Java in an applet (let alone one operated
        via JS) ..reaks of the MSVM to me..

        If that is the case 'used to worki n IE', my only advice
        to the OP is 'get used to *not* being able to do that'..

        The MSVM is no longer supported by MS, and there are
        various utilities on 'the market' for ridding one's
        Windows of this insecure pretence for Java.

        --
        Andrew Thompson
        http://www.PhySci.org/ Open-source software suite
        http://www.PhySci.org/codes/ Web & IT Help
        http://www.1point1C.org/ Science & Technology

        Comment

        Working...