IP Info Code Snippet problem

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

    IP Info Code Snippet problem

    Hi,

    I am looking at a way to return IP related information of a visitor loading
    a web page and found the following snippet of code:

    if(navigator.ja vaEnabled() && (navigator.appN ame != "Microsoft Internet
    Explorer")) {
    vartool=java.aw t.Toolkit.getDe faultToolkit();
    addr=java.net.I netAddress.getL ocalHost();
    host=addr.getHo stName();
    ip=addr.getHost Address();
    alert("Your host name is '" + host + "'\nYour IP address is " + ip);

    at http://javascript.internet.com/user-...roperties.html

    Has anyone got any experience of using these functions as I can't seem to
    get them to work.

    Cheers
    Paul.



  • Klaus Johannes Rusch

    #2
    Re: IP Info Code Snippet problem

    esrkq wrote:
    [color=blue]
    > I am looking at a way to return IP related information of a visitor loading
    > a web page and found the following snippet of code:
    >
    > if(navigator.ja vaEnabled() && (navigator.appN ame != "Microsoft Internet
    > Explorer")) {
    > vartool=java.aw t.Toolkit.getDe faultToolkit();
    > addr=java.net.I netAddress.getL ocalHost();
    > host=addr.getHo stName();
    > ip=addr.getHost Address();
    > alert("Your host name is '" + host + "'\nYour IP address is " + ip);
    >
    > at http://javascript.internet.com/user-...roperties.html
    >
    > Has anyone got any experience of using these functions as I can't seem to
    > get them to work.[/color]

    A server-side solution is generally less intrusive (starting the Java VM just
    to determine the IP address may take a little while the first time your page is
    loaded).

    --
    Klaus Johannes Rusch
    KlausRusch@atme dia.net



    Comment

    • Grant Wagner

      #3
      Re: IP Info Code Snippet problem

      esrkq wrote:
      [color=blue]
      > Hi,
      >
      > I am looking at a way to return IP related information of a visitor loading
      > a web page and found the following snippet of code:
      >
      > if(navigator.ja vaEnabled() && (navigator.appN ame != "Microsoft Internet
      > Explorer")) {
      > vartool=java.aw t.Toolkit.getDe faultToolkit();
      > addr=java.net.I netAddress.getL ocalHost();
      > host=addr.getHo stName();
      > ip=addr.getHost Address();
      > alert("Your host name is '" + host + "'\nYour IP address is " + ip);
      >
      > at http://javascript.internet.com/user-...roperties.html
      >
      > Has anyone got any experience of using these functions as I can't seem to
      > get them to work.
      >
      > Cheers
      > Paul.[/color]

      The code above only works in Netscape 4.x and Netscape 7.x (and other Gecko
      based browsers assuming the user has installed the JRE), and only works if
      client-side JavaScript and Java are enabled. If you're content targeting such a
      small audience the the code above will work fine provided you make a couple of
      modifications:

      if (navigator.java Enabled() &&
      (navigator.appN ame != "Microsoft Internet Explorer")) {
      var tool = java.awt.Toolki t.getDefaultToo lkit();
      var addr = java.net.InetAd dress.getLocalH ost();
      var host = addr.getHostNam e();
      var ip = addr.getHostAdd ress();
      alert("Your host name is '" + host + "'\nYour IP address is " + ip);
      }

      But even on the platforms it works on, all it tells the user is what they can
      already determine with winipcfg or ipconfig if they wished.

      And if you're thinking of using the IP address information to somehow identify
      users or restrict access, forget it. At work I connect to your web site from
      165.x.x.x, but your code identifies me as being on the 10.x.x.x subnet. At
      home, I connect from 24.x.x.x, but your code would tell me my IP address is
      192.168.0.2 (or .5, depending on whether I was using my desktop or laptop).

      Both 10.x.x.x and 192.168.x.x are reserved for private networks, and you're
      likely to find *lots* of users connecting from computers with IP addresses in
      those ranges.



      --
      | Grant Wagner <gwagner@agrico reunited.com>

      * Client-side Javascript and Netscape 4 DOM Reference available at:
      *


      * Internet Explorer DOM Reference available at:
      *
      Gain technical skills through documentation and training, earn certifications and connect with the community


      * Netscape 6/7 DOM Reference available at:
      * http://www.mozilla.org/docs/dom/domref/
      * Tips for upgrading JavaScript for Netscape 7 / Mozilla
      * http://www.mozilla.org/docs/web-deve...upgrade_2.html


      Comment

      Working...