Advertisement
3_2004-2005 Internet/ Browsers/ HTML #144953

Detect IP address and hostname

Detect IP address and hostname

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Detect IP address and hostname</title>
</head>
<body>
<BODY>
<!-- Script by Jayant Kumar Gandhi - www.jayantgandhi.com -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
// detect whether IE or netscape
netscapeTest = parseInt(navigator.appVersion)
explorerTest = navigator.appName.indexOf("Microsoft") + 1
// detect hostname for Netscape 3
function netscapeThree() {
if (navigator.javaEnabled()) {
userDomain = java.net.InetAddress.getLocalHostName()
return (userDomain.toString())
} else {
return null
  }
}
// detect hostname and IP address for Netscape 4
// Note here baseaddress is in format 'hostname/ip-address'
// getHostName() gets us the host name
function netscapeFour() {
if (navigator.javaEnabled()) {
baseAddress = java.net.InetAddress.getLocalHost()
userDomain = baseAddress.getHostName()
return (userDomain.toString())
} else {
return null
  }
}
if ((explorerTest == "0") && (netscapeTest == "3")) {
domainName = netscapeThree()
}
else if ((explorerTest == "0") && (netscapeTest == "4")) {
domainName = netscapeFour()
}
else {
domainName = "Domain name can be detected only on Netscape and compatible browsers. <br>Internet Explorer users must use Netscape to see the actual result"
}
document.write(domainName)
// End -->
</SCRIPT>

</body>
</html>
Original Comments (3)
Recovered from Wayback Machine