|
-
Jul 27th, 2006, 03:37 AM
#1
Thread Starter
Frenzied Member
Grab IP Address with JavaScript
Is it possible to grab a client side IP Address using JavaScript in an htm
page? I have a web page hosted on a non-php server and I want a piece of
code in JavaScript to grab the IP address of the client and send it to a web
page on another server or emailing the ip address to me. The other page will be php.
I need this for both Netscape and IE browsers.
Any ideas?
-
Jul 27th, 2006, 03:45 AM
#2
PowerPoster
Re: Grab IP Address with JavaScript
Does the Web server run any server side scripts? ASP for example?
-
Jul 27th, 2006, 03:46 AM
#3
Re: Grab IP Address with JavaScript
 Originally Posted by tony007
Is it possible to grab a client side IP Address using JavaScript in an htm page?
Maybe, not sure, but...
 Originally Posted by tony007
I want a piece of
code in JavaScript to grab the IP address of the client and send it to a web
page on another server
Not possible, JS HTTP requests can only be made to the domain the page is served from.
 Originally Posted by tony007
or emailing the ip address to me.
Also not possible.
-
Jul 27th, 2006, 03:47 AM
#4
Thread Starter
Frenzied Member
Re: Grab IP Address with JavaScript
 Originally Posted by rory
Does the Web server run any server side scripts? ASP for example?
Thank u for u reply. The one that has the html page does not support any scripting but the other supports php and both are in freee webhosting. I be happy if u show me how to get ip of client upon vision and send it to myemial or send it webserver that supports php for inserting it to mysql or email it some how. Thanks
-
Jul 27th, 2006, 03:57 AM
#5
Re: Grab IP Address with JavaScript
If you have Server Side Includes (SSI/SHTML) then you can do:
HTML Code:
<script type="text/javascript">
var ip = '<!--#echo var=REMOTE_ADDR -->';
alert('Your IP is ' + ip);
</script>
What happens here is that before the page is sent by the server, the SSI parses the page, finds the #echo statement and replaces the HTML comment with IP address of the client. Thus JavaScript on the client machine is like var ip = '0.0.0.0';
Most often SSI must be enabled separately for .htm and .html pages, this can be done using .htaccess. Or just use .shtml.
Last edited by Merri; Jul 27th, 2006 at 06:51 AM.
-
Jul 27th, 2006, 04:05 AM
#6
PowerPoster
Re: Grab IP Address with JavaScript
i dont know anything bout Php but you could use an img tag to run a remote script .. cant say for sure 100% if it will get the IP though ...
<img src="http://www.someurl.com/mypage.php" border="0" with="1" height="1">
-
Jul 27th, 2006, 04:11 AM
#7
PowerPoster
Re: Grab IP Address with JavaScript
another option ..
<SCRIPT>
var ip = new java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip);
document.writeln(ipStr.substring(ipStr.indexOf("/")+1));
</SCRIPT>
-
Jul 27th, 2006, 04:13 AM
#8
Re: Grab IP Address with JavaScript
That returns the internal (LAN) IP, not the remote address.
Additionally, it takes an eternity to run.
-
Jul 27th, 2006, 04:19 AM
#9
PowerPoster
Re: Grab IP Address with JavaScript
 Originally Posted by penagate
That returns the internal (LAN) IP, not the remote address.
Additionally, it takes an eternity to run.
oh well .. blame google ..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|