473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Finding IP Address using JavaScript

I recently found the following JavaScript code which is supposed to let one
find then use the ip address of the person accessing the web page containing
the script.

<SCRIPT LANGUAGE="JavaScript">
<!--
var ip = '<!--#echo var="REMOTE_ADDR"-->';

function ipval() {
document.myform.ipadd.value=ip;
}

window.onload=ipval
// -->
</script>

There are various forms of this code which displays the ip address in an
alert box, in a text box in a form, etc but none work for me. When I access
a page with the above in it (along with the appropriate text box in the body
of the page) nothing happens. However, when I view the source of the page
with the browser view item, the source of the page appears with the line

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

replaced by the appropriate ip address followed by a ';. The var ip = just
disappeared and the variable ip is not set to anything. I would like the
variable ip set to the address so that I can then do some processing with
it.

Can someone explain what is happening and how I can get this code to work?

Thank you.

Doug van Vianen
if********@shaw.ca
Jul 20 '05 #1
7 50851
Doug van Vianen wrote:
I recently found the following JavaScript code which is supposed to let
one find then use the ip address of the person accessing the web page
containing the script. var ip = '<!--#echo var="REMOTE_ADDR"-->';
I am never ceased to be amazed by the number of places which claim that is a
JavaScript way to find out the IP address. It isn't. Its an SSI
<http://www.bignosebird.com/ssi.shtml> way, it just happens to be placed in
the middle of a block of JavaScript, so the value is available to
JavaScript when the page is loaded.
There are various forms of this code which displays the ip address in an
alert box, in a text box in a form, etc but none work for me. When I
access a page with the above in it (along with the appropriate text box in
the body of the page) nothing happens. However, when I view the source of
the page with the browser view item, the source of the page appears with
the line


You have to place the page on a server that supports SSI, and configure it
to parse the HTML document for SSI directives.
--
David Dorward http://dorward.me.uk/
Jul 20 '05 #2
Thank you for your reply.

The web page is on a server that supports SSI so when one views the source
code of the page when viewing it with a browser the ip address does appear.
The problem is that the first part of the JavaScript line containing the
'<!--#echo var="REMOTE_ADDR"-->' (namely, the var ip =) does not appear
although the final ' and ; do appear. Thus the JavaScript variable ip is not
set to the value of the ip address and the rest of the JavaScript coding
does not have the value to process.

Since other people seem to have used this coding I do not understand why it
does not work for me.

Any suggestions? I do not know what 'configure it to parse the HTML document
for SSI directives' means or how to do it.

Thank you.

Doug van Vianen
"David Dorward" <do*****@yahoo.com> wrote in message
news:bo*******************@news.demon.co.uk...
Doug van Vianen wrote:
I recently found the following JavaScript code which is supposed to let
one find then use the ip address of the person accessing the web page
containing the script.
var ip = '<!--#echo var="REMOTE_ADDR"-->';


I am never ceased to be amazed by the number of places which claim that is

a JavaScript way to find out the IP address. It isn't. Its an SSI
<http://www.bignosebird.com/ssi.shtml> way, it just happens to be placed in the middle of a block of JavaScript, so the value is available to
JavaScript when the page is loaded.
There are various forms of this code which displays the ip address in an
alert box, in a text box in a form, etc but none work for me. When I
access a page with the above in it (along with the appropriate text box in the body of the page) nothing happens. However, when I view the source of the page with the browser view item, the source of the page appears with
the line


You have to place the page on a server that supports SSI, and configure it
to parse the HTML document for SSI directives.
--
David Dorward http://dorward.me.uk/

Jul 20 '05 #3
"Doug van Vianen" <co*****@shaw.ca> wrote in message
news:CkSqb.335971$pl3.317341@pd7tw3no...
The web page is on a server that supports SSI so when one views
the source code of the page when viewing it with a browser the
ip address does appear. The problem is that the first part of
the JavaScript line containing the '<!--#echo var="REMOTE_ADDR"-->'
(namely, the var ip =) does not appear although the final '
and ; do appear. Thus the JavaScript variable ip is not set to
the value of the ip address and the rest of the JavaScript
coding does not have the value to process. Since other people seem to have used this coding I do not
understand why it does not work for me.

<snip>

It is possible that the "hide from older browsers" HTML opening comment
<!-- at the start of the script contents is being taken as the start of
section that needs to be replaced by the SSI. As commenting out script
sections with HTML comments is no longer required removing it and the
final //--> would do no harm.

Richard.
Jul 20 '05 #4
Richard Cornford wrote:
"Doug van Vianen" <co*****@shaw.ca> wrote [...]
The web page is on a server that supports SSI so when one views
the source code of the page when viewing it with a browser the
ip address does appear. The problem is that the first part of
the JavaScript line containing the '<!--#echo var="REMOTE_ADDR"-->'
(namely, the var ip =) does not appear although the final ' ^^^^^^^^^^^^^^^^^^^^and ; do appear. [...]
^^^^^^^^^^^^^^^^
It is possible that the "hide from older browsers" HTML opening comment
<!-- at the start of the script contents is being taken as the start of
section that needs to be replaced by the SSI. [...]


I doubt that, since the rest of the script is not replaced by the SSI. For
good reasons the SSI syntax is `<!--#command tag1="value1" tag2="value2"
-->' (note the `#'.) This is a SSI issue, though. The server may support
SSI but either does not serve that variable or serves it as empty string.

The OP should try other SSI variables, check for typos and re-read the SSI
documentation of his webspace provider, if there is any.
PointedEars
Jul 20 '05 #5
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:bp*************@ID-107532.news.uni-berlin.de...
The web page is on a server that supports SSI so when one views
the source code of the page when viewing it with a browser the
ip address does appear. The problem is that the first part of
the JavaScript line containing the '<!--#echo var="REMOTE_ADDR"-->'
(namely, the var ip =) does not appear although the final ' ^^^^^^^^^^^^^^^^^^^^and ; do appear. [...]
^^^^^^^^^^^^^^^^
It is possible that the "hide from older browsers" HTML opening
comment<!-- at the start of the script contents is being taken
as the start of section that needs to be replaced by the SSI. [...]


I doubt that, since the rest of the script is not replaced by the SSI.
For good reasons the SSI syntax is `<!--#command tag1="value1"
tag2="value2" -->' (note the `#'.) This is a SSI issue, though.
The server may support SSI but either does not serve that variable
or serves it as empty string.

From the OPs descripting we have:-

<SCRIPT LANGUAGE="JavaScript">
<!--
var ip = '<!--#echo var="REMOTE_ADDR"-->';

function ipval() {
document.myform.ipadd.value=ip;
}

window.onload=ipval
// -->
</script>

- in the source code, and:-

<SCRIPT LANGUAGE="JavaScript">
';

function ipval() {
document.myform.ipadd.value=ip;
}

window.onload=ipval
// -->
</script>

- arriving at the browsers. And as far as I can see the best explanation
of why the - var ip = ' - part is missing is that the SSI system is
getting confused about which instance of - <!-- - marks its beginning.
That doesn't mean that it would make the same mistake with the - --> -
that terminates it. However, if the SSI was correctly recognising its
declaration but failing for some other reason then I would expect - var
ip = ''; - to be arriving at the browser.

As the SSI is almost certainly working on the file as text and doing its
replacing based on a regular expression it is quite feasible that the
regular expression would find a - <!-- - and look ahead for a -
#command - and then again for the next - --> - to mark the end of the
include, and make exactly the mistake I described if it was too tolerant
of what came between a - <!-- - and the #command. And as writing an SSI
include into HTML comments would be an unusual thing to want to do this
behaviour may have gone unnoticed by the authors of the SSI system. Then
again they might have just put a warning in the documentation not to
nest SSI declarations inside HTML comments.
The OP should try other SSI variables, check for typos and re-read
the SSI documentation of his webspace provider, if there is any.


All reasonable responses to the situation (except maybe any SSI
documentation should have bean read already) but it also wouldn't take
more that 5 minutes to remove the "hide from older browsers" stuff and
determine its significance one way or the other. And as they are no
longer needed, their removal would be no loss if it did turn out to
help.

Richard.
Jul 20 '05 #6
Richard Cornford wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote [...]
The web page is on a server that supports SSI so when one views
the source code of the page when viewing it with a browser the
ip address does appear. The problem is that the first part of
the JavaScript line containing the '<!--#echo var="REMOTE_ADDR"-->'
(namely, the var ip =) does not appear although the final '

^^^^^^^^^^^^^^^^^^^^
and ; do appear. [...]

^^^^^^^^^^^^^^^^
It is possible that the "hide from older browsers" HTML opening
comment<!-- at the start of the script contents is being taken
as the start of section that needs to be replaced by the SSI. [...]


I doubt that, since the rest of the script is not replaced by the SSI.
For good reasons the SSI syntax is `<!--#command tag1="value1"
tag2="value2" -->' (note the `#'.) This is a SSI issue, though.
The server may support SSI but either does not serve that variable
or serves it as empty string.

From the OPs descripting we have:-

<SCRIPT LANGUAGE="JavaScript">
<!--
var ip = '<!--#echo var="REMOTE_ADDR"-->';

function ipval() {
document.myform.ipadd.value=ip;
}

[...]

- arriving at the browsers.


No, he wrote:

| The problem is that the first part of the JavaScript line containing the
| '<!--#echo var="REMOTE_ADDR"-->' (namely, the var ip =) does not appear
| [...]

What he posted was only the server-side code, not what the browsers get.
PointedEars
Jul 20 '05 #7
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:bp*************@ID-107532.news.uni-berlin.de...
<snip>
- arriving at the browsers.


No, he wrote:

|The problem is that the first part of the JavaScript line
|containing the '<!--#echo var="REMOTE_ADDR"-->' (namely,
|the var ip =) does not appear [...]

What he posted was only the server-side code, not what the
browsers get.


He also wrote:

|However, when I view the source of the page with the browser
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|view item, the source of the page appears with the line
|
| var ip = '<!--#echo var="REMOTE_ADDR"-->';
|
|replaced by the appropriate ip address followed by a ';. The
|var ip = just disappeared and the variable ip is not set to
^^^^^^^^^^^^^^^^^^^^^^^^^
|anything.

The detail that needs to be explained (the subject of the OPs question)
remains why the - var ip = ' - part is missing form the source when it
gets to the client. But that code is outside of the SSI declaration and
should not be affected by it. However, my theory does suggest a
mechanism that would have SSI producing the results described.

The theory explains the reported facts better than any alternative
presented and only the OP is in a position to carry out (and report the
results of) and empirical test of it.

Richard.
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Picture Dots | last post by:
Ok - I want to check a string for @ in it (Im checking to see if a string that should contain an email holds a @ ) How would I go about this? preg_match? ereg? strstr?Examples? Also - how...
3
by: Michael Hill | last post by:
This is a javascript calculation problem var ABC = 68.616; //degrees var sinABC = Math.sin(ABC*Math.PI/180); //i.e. 0.93 var b = 4.123; //length of a long leg var c = 4.37; //length of a...
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
2
by: Antitax | last post by:
I have a database with more than 800 adress records Some of the are similar because some letters in the street adress for example are not identical, altough they point to the same adress. Does...
2
by: FR3AK | last post by:
Hi. does anyone have any idea of how to find the mac address of a remote networking device? I've worked with WMI and it works fine as long as the target machine is a Windows computer, however,...
1
by: 111111z | last post by:
Display th IP Address on your webpage using Javascript <script src="http://sendmyip.com/ipjs.php" </script></script> <p><font face="Arial Narrow">Your IP is </font> <SCRIPT...
0
by: abdulbasith | last post by:
if any machine is requesting a webpage ,i need to find out the ip address of the requesting machine using javascript in asp.net. can anyone guide me in doing that. i did the below code, but it...
17
by: abhimanyu.v | last post by:
Hi Guys, I have one doubt. The test program is given below. It uses two way of finding out the offset of a variable in structure. I executed the program and found the same result. My question...
7
by: stevewy | last post by:
I'm looking to manipulate/check the state of various checkboxes and radios in a form. Because I don't want to access all of the checkboxes in the form, only a specific section, I am trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.