-
April 21st, 2002, 06:41 AM
#1
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
-
April 21st, 2002, 10:25 AM
#2
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
-
April 21st, 2002, 03:11 PM
#3
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?
-
May 7th, 2002, 01:40 PM
#4
Member
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!
-
May 12th, 2002, 08:08 PM
#5
I don't use javascript much, but im sure you can find IP dection scripts at
http://www.planet-source-code.com.
System_0verload
-
May 24th, 2002, 01:56 AM
#6
Senior Member
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
.
-
May 25th, 2002, 09:28 PM
#7
If you were using PHP, I believe this would work
PHP Code:
<?php
echo $REMOTE_ADDR;
?>
-
May 29th, 2002, 07:19 AM
#8
Junior Member
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-
-
May 29th, 2002, 07:19 AM
#9
Junior Member
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-
-
June 27th, 2002, 01:03 AM
#10
Member
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
-
Forum Rules
|
|