Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing a client's IP address

Status
Not open for further replies.

MadPerch

Programmer
Sep 13, 2000
2
US
Does anyone know of a way to grab a client's ip address using client side script through Internet Explorer? I know there is a way through netscape but that solution does not work with IE. Any help would be greatly appreciated. [sig][/sig]
 
1) What is the method in NN. Maybe someone could come up with a similar technique in IE.

2) If you can get your website on an ASP server this becomes exceedingly easy.

3) There may be a way to do this with Windows Scripting Host by running a command line with ping localhost, redirect this to a file, parse out the file to find the ip address (with brackets [xxx.xxx.xxx.xxx]). This would, however, pop up a security warning to the user.

Good luck,
[sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
The solution for netscape is:

if ((navigator.appVersion.indexOf(&quot;4.&quot;) != -1) && (navigator.appName.indexOf(&quot;Netscape&quot;) != -1)){
ip = &quot;&quot; + java.net.InetAddress.getLocalHost().getHostAddress();
document.write(&quot;Your IP address is &quot; + ip);
}
else {
//document.write(&quot;IP Address only shown in Netscape with Java enabled!&quot;);
} [sig][/sig]
 
In ASP, the Request Object provides a collection called - ServerVariables. This can be used to get the client address as the standard HTTP headers are defined as members of the ServerVariables. The following code would give the client's IP address:

Users's IP Address :
<% Request.ServerVariables(&quot;REMOTE_ADDR&quot;) %>

Hope this helps [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top