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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client IP Grabbing

Status
Not open for further replies.

zeebow

Programmer
May 20, 2001
9
0
0
MT
Hi,

I am trying to find a way on how to be able to grab the IP address. I have found some javascript samples for netscape but none for explorer!!! Any help is appreciated.

Cheers
Chris
 
Place this in the <body> of your document:<body>
<script language=&quot;javascript&quot;>

var ip = '<!--#echo var=&quot;REMOTE_ADDR&quot;-->'

function ipval() {
document.myform.ipaddr.value=ip;
}
window.onload=ipval
</script>


<form method=&quot;post&quot; action name=&quot;myform&quot;>
<p><input type=&quot;text&quot; name=&quot;ipaddr&quot; readonly size=&quot;20&quot;> </p>
</form>
</body>

You must use .shtml file extension instead of .html or .htm. It works great. I'm now looking for a script that captures the host name. If you run across anything let me know.

Good luck!

 
Hey SpiderWoman,

I guess since you can use 'REMOTE_ADDR' you could also do 'REMOTE_HOST':

Code:
var host = '<!--#echo var=&quot;REMOTE_HOST&quot;-->'

function hostval()
{
document.form.hostvalue.value=host
}
 
Hi SpiderWonam,
This is a good code to get the IP address and the host name:
Hope it works!

<script>

/* There are a few instances in which the browser cannot ascertain the user's address, so we will instruct the browser to ignore errors by setting the onerror handler to null: */
window . onerror = null;

/* We will also give hostaddress and hostname a default value in case the address look-up fails: */
hostaddress = hostname = &quot;(unknown)&quot;;

/* Now we will try to gather the host information: */
localhost = java . net . InetAddress . getLocalHost ();
hostaddress = localhost . getHostAddress ();
hostname = localhost . getHostName ();

/* The Java methods used above are capable of throwing exceptions. When Java exceptions occur within JavaScript, the script body is aborted. In order to make sure that the following statements get a chance to execute, we must include them in a separate script body: */

</script>

<script>

document . writeln (&quot;<p>Your IP address is <b>&quot; + hostaddress + &quot;</b>.</p>&quot;);
document . writeln (&quot;<p>Your hostname is <b>&quot; + hostname + &quot;</b>.</p>&quot;);

</script>


It gives the Next result:

Your IP address is (unknown).

Your hostname is (unknown). sbayter
 
The upper code doesn't work under IE.
Here:
<object classid=clsid:{248DD896-BB45-11CF-9ABC-0080C7E7B78D} name=winsock onerror='alert(&quot;You have no this COM.&quot;)'></object>
<script>alert(winsock.localIP)</script> Coding is the worst thing I had done.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top