-
Does anyone have a java script for displaying a visitor's IP address?
I would like to add this feature to my site
-
Here, I found this code on some free script website. The user has to be using Netscape and have Java enabled however.
Code:
<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>
-
I have a really bad feeling that it is only possible using a Java enabled engine!! :( but I will keep looking for you Daniel.
-
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.
-
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....
-
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.
-
Really... I have not really looked into it... I can't get to it from my work comp.. I will keep searching!