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

Determining an IP address in JavaScript

Status
Not open for further replies.

vellad

Programmer
Jul 5, 2000
4
AU
How do you determine an IP address in JavaScript?
 
I have no idea, I know you can do it in Java and with Jscript ASP. Might wanna try those.<br><br><A HREF="mailto:-jared@aauser.com">-jared@aauser.com</A>
 
What is the context, can you be more specific? What IP address and when do you wan't it? <br><br>-pete
 
do you mean in the sense of an environment variable? <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
I would agree with imotic's question. Like in Perl you have environment variables, I am not sure about JavaScript.<br><br>And I know that any CGI scripting language can do it since it communicates with the server, but I am not sure about JS.<br><br>-Vic
 
It is possible with serverside javascript. There are some environmental variables you can access quite easily using ASP and jscript, one of them containing the IP of the user.<br><br><br><A HREF="mailto:jared@aauser.com">jared@aauser.com</A><br><br>
 
Check DevHead on ZDnet and found this Nutscrap only option:<br><br>&lt; d e v h e a d : s c r i p t l i b r a r y &gt;<br><br>Script: 0344<br>Type: JavaScript<br>------------------------------------------------<br><br>To install this script, follow this simple step:<br><br>1. Cut and paste this into the BODY of your document:<br><br>&lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;<br>&lt;!-- Begin<br><br>&lt;!-- This script and many more are available free online at --&gt;<br>&lt;!-- The JavaScript Source!! <A HREF=" TARGET="_new"> --&gt;<br><br>if ((navigator.appVersion.indexOf(&quot;4.&quot;) != -1) && (navigator.appName.indexOf(&quot;Netscape&quot;) != -1)){ <br>ip = &quot;&quot; + java.net.InetAddress.getLocalHost().getHostAddress();<br>document.write(&quot;Your IP address is &quot; + ip);<br>}<br>else {<br>document.write(&quot;IP Address only shown in Netscape with Java enabled!&quot;);<br>}<br>//&nbsp;&nbsp;End --&gt;<br>&lt;/script&gt;<br><br>------------------------------------------------<br>ZDNet (c) 1999. DevHead and ScriptLibrary provides<br>these scripts as a free service to our users. The<br>scripts have been provided by the author for use<br>within the resource and are &quot;freely distributable.&quot; <br>Scripts remain the property of the author, unless <br>otherwise indicated.<br><br><br>Does this help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top