Click to See Complete Forum and Search --> : Does anyone have a java script for displaying a visitor's IP address?
Daniel_Christie
Nov 13th, 2000, 02:01 PM
Does anyone have a java script for displaying a visitor's IP address?
I would like to add this feature to my site
Wynd
Apr 23rd, 2001, 08:54 PM
Here, I found this code on some free script website. The user has to be using Netscape and have Java enabled however.
<script language="javascript">
<!--
netscapeTest = parseInt(navigator.appVersion)
explorerTest = navigator.appName.indexOf("Microsoft") + 1
function netscapeThree() {
if (navigator.javaEnabled()) {
userDomain = java.net.InetAddress.getLocalHostName()
txt = "I bet your hostname is " + (userDomain.toString()) + " !";
} else {
txt = "You are browsing without Java enabled and therefore I can\'t find out what your hostname is.";
}
}
function netscapeFour() {
if (navigator.javaEnabled()) {
baseAddress = java.net.InetAddress.getLocalHost()
userDomain = baseAddress.getHostName()
txt = "I bet your hostname is " + (userDomain.toString()) + " !";
} else {
txt = "You are browsing without Java enabled and therefore I can\'t find out what your hostname is."; }
}
if ((explorerTest == "0") && (netscapeTest == "3")) { netscapeThree() }
else if ((explorerTest == "0") && (netscapeTest == "4")) { netscapeFour() }
else {
txt = "It appears you are using Internet Explorer - and we can not find your hostname in that browser."
}
alert(txt)
</script>
chrismitchell
Apr 24th, 2001, 02:44 AM
I have a really bad feeling that it is only possible using a Java enabled engine!! :( but I will keep looking for you Daniel.
JoshT
Apr 24th, 2001, 06:44 AM
I wouldn't think javascript could get the local ip address, as it could be a security risk. If you're running a firewall and all web requests from your department's 50 computers use the firewalls ip address though NAT, a hacker could use the javascript to fill a hidden field in a form to enumerate your network through the firewall if he could get your users to go to his web page.
chrismitchell
Apr 24th, 2001, 07:20 AM
There is a way round it but it requires going to a site called www.thecounter.com... they will do it for you for free... It will give you results for IP address of users, popularity of pages etc....
JoshT
Apr 24th, 2001, 08:41 AM
Yeah, but on a server-side program like thecounter, you would get the firewall's ip address in my scenario, not the local ip address. The REMOTE_HOST or REMOTE_ADDR CGI variables can get the ip address of the web request easy enough in most web server technologies (Perl, ASP, etc.), but javascript interacts locally on the client.
chrismitchell
Apr 24th, 2001, 09:27 AM
Really... I have not really looked into it... I can't get to it from my work comp.. I will keep searching!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.