Grab IP Address with JavaScript

L

Larry R. Baker

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-ASP 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. The other page will be ASP.

I need this for both Netscape and IE browsers.

Any ideas?
 
R

Ray at

Personally, I don't know. Try asking in a client-side group such as
..scripting.jscript.

Ray at work
 
R

Randy Rahbar

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-ASP 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. The other page will be ASP.

Off topic, but yes, it's possible but you need more than Javascript. We do
it here using a Java Applet. We grab the IP with the trusted applet, then
using Javascript we write it to a cookie.
 
R

Ray at

The server that's hosting the asp page can get the IP address from the
request.servervariables("remote_addr"). Of course, if the client machine is
behind a firewall, the client-side resolved IP would be different. But
unless that matters, let the server do it.

Ray at work
 
L

ljb

I tried the following client side but it didn't seem 100% reliable. Seems
not everyone has Winsock installed.

strIP = CreateObject("MSWinsock.Winsock").LocalIP

If this thread moves to another group I don't want to lose track since I
haven't solved the problem yet.

LJB
 
L

Larry R. Baker

Hey guys sorry if this is off topic, I theorized that since I was sending to
ASP that it would be on target.

Again I apologize.

Larry

I will repost in the other group.
 
L

Larry R. Baker

Hey guys thanks again, the consensus is that the server has to handle this
and not the client side. I had hoped to avoid this in order to cut down on
processing overhead but that's life.

Larry
 
R

Ray at

Request.ServerVariables("REMOTE_ADDR") will return the IP that the http
request comes from. This is not necessarily the primary IP of the primary
NIC in the computer with the browser. It could be a firewall, a proxy
server, a router, etc., but this may not matter.

ip.asp:

<%
Response.Write "Your IP address is " &
Request.ServerVariables("REMOTE_ADDR")
%>


Ray at home
 
R

Roland Hall

If you user has disabled scripting, you'll cut down on the client-side
processing too.

Hey guys thanks again, the consensus is that the server has to handle this
and not the client side. I had hoped to avoid this in order to cut down on
processing overhead but that's life.

Larry
 
G

Guest

Randy Rahbar said:
Off topic, but yes, it's possible but you need more than Javascript. We do
it here using a Java Applet.
to a cookie.
Randy could you point me to a link on creating cookies? I need to create a
cookie for time and visit tracking, and I am clueless on how to create
cookie let alone use them.

BOB
 
R

Randy Rahbar

Randy could you point me to a link on creating cookies? I need to create a
cookie for time and visit tracking, and I am clueless on how to create
cookie let alone use them.

To write the cookie using server-side vbscript:
Response.Cookie("myCookie") = "This cookie is good!"

Now to read the cookie using server-side vbscript:
myVariable = Response.Cookie("myCookie")
 
R

Randy Rahbar

Now to read the cookie using server-side vbscript:
myVariable = Response.Cookie("myCookie")

Eep, I screwed up all together there (I'll blame it on the lack of coffee
this morning). Try this instead:

To write the cookie using vbscript:
Response.Cookies("myCookie") = "This cookie is REALLY good!"

Now to read the cookie using vbscript:
myVariable = Request.Cookies("myCookie")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top