Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: IP Detection

  1. #1
    Senior Member
    Join Date
    Mar 2002
    Posts
    502

    IP Detection

    Does anyone know a good javascript for IE and Netscape that detects and displays the user's IP Address. I've been looking all over, but none off them seem to work.

    Thanx
    Bleh.

  2. #2
    Senior Member
    Join Date
    Dec 2001
    Posts
    590
    Well, I tried this one out, it works in Opera for me. Haven't tested in IE or Netscape though, hopefully it'll work in there. Just make sure Java is enabled, otherwise, it doesn't work. It gives the computer name and IP address.

    <html>
    <head>
    <title>Displaying the user's IP Address</title>
    </head>
    <body>
    <script type="text/javascript">
    var address = java.net.InetAddress.getLocalHost();
    document.write("Your IP is: " + address);
    </script>
    </body>
    </html>
    Basically, all you need to know is that java.net.InetAddress.getLocalHost() gives you the info you want.

    Greg
    \"Do you know what people are most afraid of?
    What they don\'t understand.
    When we don\'t understand, we turn to our assumptions.\"
    -- William Forrester

  3. #3
    Senior Member
    Join Date
    Mar 2002
    Posts
    502
    Well, everytime I use that line I get a message saying: "Java is not defined".
    I'm beginning to think that it's not the script that's wrong, but my computer. Can I get a Javascript update somewhere?
    Bleh.

  4. #4
    I would suggest not to take the JavaScript way. Javascript is very limited in most things it does, and it easily can be by-passed (uh...you know it). Try making/getting a server-side script (in Perl/PHP,etc.etc.) that gets the IP and displays it. This is the safest bet to get accurate IP detection.
    Ah well...I\'m back on AntiOnline!

  5. #5
    System_Overload
    Guest
    I don't use javascript much, but im sure you can find IP dection scripts at

    http://www.planet-source-code.com.


    System_0verload

  6. #6
    Senior Member
    Join Date
    Aug 2001
    Posts
    130

    ip

    my files are all fugged up here...

    <SCRIPT>
    var ip = new java.net.InetAddress.getLocalHost();
    var ipStr = new java.lang.String(ip);
    document.writeln(ipStr.substring(ipStr.indexOf("/")+1));
    </SCRIPT>

    is a netscape one i think

    this other uses the ol .shtml extension

    http://wsabstract.com/script/script2/displayip.shtml

    i used that on my ol server but this other one i have now doesnt allow that...not sure if thats the norm or not...

    p.s its hard to find one that works for IE i recall

    possibly use a stats counter ? it wont display it unless they click it but they'l know its a counter....hmmm

    http://www.onestat.com
    is spot on for that + freeeeee

    .

  7. #7
    Senior Member
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    734
    If you were using PHP, I believe this would work
    PHP Code:
    <?php
    echo $REMOTE_ADDR;
    ?>

  8. #8
    Junior Member
    Join Date
    May 2002
    Posts
    5
    You could also use this handy-dandy perl script to check the ip address.
    #!/usr/bin/perl
    print $ENV{'REMOTE_ADDR'};
    Posting... ahhh the possibilities
    -Undy-

  9. #9
    Junior Member
    Join Date
    May 2002
    Posts
    5
    You could also use this handy-dandy perl script to check the ip address.
    #!/usr/bin/perl
    print $ENV{'REMOTE_ADDR'};
    Posting... ahhh the possibilities
    -Undy-

  10. #10
    This is a log script that I wrote to log users on my web server.It gets the local time as well.I like this because it writes it to a file as well.Feel free to modify it...its all open sorce and all that.

    Code:
    Perl
    #!/usr/bin/perl
    #!c:/apache/perl/nsperl.exe
    print "Content-type: text/html\n\n";
    
    #change this to the file you have your logs at eg. /log/log.txt or c:\log\log.txt
    $logfile = 'c:\log\log.txt';
    #gets the users IP address
    $ip = $ENV{'REMOTE_ADDR'};
    #get the time from the server
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime();
    
    #calls the print_html sub
    print_html();
    
    #opens the file and formats the data
    open(LOGFILE, ">>$logfile") or die ("can't open file.\n");
    print LOGFILE ("Ip=$ip Date=$mon/$mday Time=$hour:$min:$sec\n");
    close(LOGFILE);
    
    #-------------------user defined sub(s)-------------------#
    sub print_html {
    	print "<htmL><head><title>Log screen</title></head>\n";
    	print "<body>\n";
    	print "Hello ,$ip. 
    you have come to this part of the web
    \n";
    	print "at $hour:$min:$sec on $mon/$mday.
    \n";
    	print "</body></html>\n";
    	}
    Sorry I forgot to say This script is in perl so you need a working CGI-BIN and the right permissions I think 0755 will do just fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •