Click to See Complete Forum and Search --> : IP Detection
Sick Dwarf
April 21st, 2002, 07:41 AM
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
hot_ice
April 21st, 2002, 11:25 AM
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
Sick Dwarf
April 21st, 2002, 04:11 PM
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?
Manish
May 7th, 2002, 02:40 PM
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.
System_Overload
May 12th, 2002, 09:08 PM
I don't use javascript much, but im sure you can find IP dection scripts at
http://www.planet-source-code.com.
System_0verload
Ron the don
May 24th, 2002, 02:56 AM
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 :D
.
jethro
May 25th, 2002, 10:28 PM
If you were using PHP, I believe this would work
<?php
echo $REMOTE_ADDR;
?>
Undy
May 29th, 2002, 08:19 AM
You could also use this handy-dandy perl script to check the ip address.
#!/usr/bin/perl
print $ENV{'REMOTE_ADDR'};
Undy
May 29th, 2002, 08:19 AM
You could also use this handy-dandy perl script to check the ip address.
#!/usr/bin/perl
print $ENV{'REMOTE_ADDR'};
a_420_hacker_24
June 27th, 2002, 02:03 AM
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.
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.
Mallam
July 11th, 2002, 03:46 PM
ehmm,
That must be great work dude! a_420_hacker_24
Bingo.
Gurl
July 11th, 2002, 03:53 PM
Perhaps these will work for you:
I think this one only works in IE...
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var ip = '';
alert("Your IP address is "+ip);
window.defaultStatus = "Your IP address is "+ip;
document.write("<title>Your IP address is "+ip+"</title>");
</script>
</head>
<body>
<p align="center">IP Address In IE</p>
</body>
</html>
This one only works in Netscape...
<html>
<head>
<title>IP Address In Netscape</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
if ((navigator.appVersion.indexOf("4.") != -1) && (navigator.appName.indexOf("Netscape") != -1)){
ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();
document.write("Your IP address is " + ip);
}
else {
document.write("IP Address Is Only Displayed In Netscape!");
}
</script>
</body>
</html>
Hope this helps~! :)
ArmyOfOne
July 11th, 2002, 03:56 PM
yes, nice little program, I'm currently learning perl and am struggling trying to find practical uses, but I could of done that! Nice idea a_420_hacker_24, thanks for the inspiration. :D