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
Printable View
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
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.
Basically, all you need to know is that java.net.InetAddress.getLocalHost() gives you the info you want.Quote:
<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>
Greg
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?
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.
I don't use javascript much, but im sure you can find IP dection scripts at
http://www.planet-source-code.com.
System_0verload
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
.
If you were using PHP, I believe this would work
PHP Code:<?php
echo $REMOTE_ADDR;
?>
You could also use this handy-dandy perl script to check the ip address.
Quote:
#!/usr/bin/perl
print $ENV{'REMOTE_ADDR'};
You could also use this handy-dandy perl script to check the ip address.
Quote:
#!/usr/bin/perl
print $ENV{'REMOTE_ADDR'};
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.
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.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";
}
ehmm,
That must be great work dude! a_420_hacker_24
Bingo.
Perhaps these will work for you:
I think this one only works in IE...
This one only works in Netscape...Code:<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>
Hope this helps~! :)Code:<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>
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