473,466 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IP Info Code Snippet problem

Hi,

I am looking at a way to return IP related information of a visitor loading
a web page and found the following snippet of code:

if(navigator.javaEnabled() && (navigator.appName != "Microsoft Internet
Explorer")) {
vartool=java.awt.Toolkit.getDefaultToolkit();
addr=java.net.InetAddress.getLocalHost();
host=addr.getHostName();
ip=addr.getHostAddress();
alert("Your host name is '" + host + "'\nYour IP address is " + ip);

at http://javascript.internet.com/user-...roperties.html

Has anyone got any experience of using these functions as I can't seem to
get them to work.

Cheers
Paul.

Jul 20 '05 #1
2 7625
esrkq wrote:
I am looking at a way to return IP related information of a visitor loading
a web page and found the following snippet of code:

if(navigator.javaEnabled() && (navigator.appName != "Microsoft Internet
Explorer")) {
vartool=java.awt.Toolkit.getDefaultToolkit();
addr=java.net.InetAddress.getLocalHost();
host=addr.getHostName();
ip=addr.getHostAddress();
alert("Your host name is '" + host + "'\nYour IP address is " + ip);

at http://javascript.internet.com/user-...roperties.html

Has anyone got any experience of using these functions as I can't seem to
get them to work.


A server-side solution is generally less intrusive (starting the Java VM just
to determine the IP address may take a little while the first time your page is
loaded).

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #2
esrkq wrote:
Hi,

I am looking at a way to return IP related information of a visitor loading
a web page and found the following snippet of code:

if(navigator.javaEnabled() && (navigator.appName != "Microsoft Internet
Explorer")) {
vartool=java.awt.Toolkit.getDefaultToolkit();
addr=java.net.InetAddress.getLocalHost();
host=addr.getHostName();
ip=addr.getHostAddress();
alert("Your host name is '" + host + "'\nYour IP address is " + ip);

at http://javascript.internet.com/user-...roperties.html

Has anyone got any experience of using these functions as I can't seem to
get them to work.

Cheers
Paul.


The code above only works in Netscape 4.x and Netscape 7.x (and other Gecko
based browsers assuming the user has installed the JRE), and only works if
client-side JavaScript and Java are enabled. If you're content targeting such a
small audience the the code above will work fine provided you make a couple of
modifications:

if (navigator.javaEnabled() &&
(navigator.appName != "Microsoft Internet Explorer")) {
var tool = java.awt.Toolkit.getDefaultToolkit();
var addr = java.net.InetAddress.getLocalHost();
var host = addr.getHostName();
var ip = addr.getHostAddress();
alert("Your host name is '" + host + "'\nYour IP address is " + ip);
}

But even on the platforms it works on, all it tells the user is what they can
already determine with winipcfg or ipconfig if they wished.

And if you're thinking of using the IP address information to somehow identify
users or restrict access, forget it. At work I connect to your web site from
165.x.x.x, but your code identifies me as being on the 10.x.x.x subnet. At
home, I connect from 24.x.x.x, but your code would tell me my IP address is
192.168.0.2 (or .5, depending on whether I was using my desktop or laptop).

Both 10.x.x.x and 192.168.x.x are reserved for private networks, and you're
likely to find *lots* of users connecting from computers with IP addresses in
those ranges.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #3

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

Similar topics

4
by: Rob Conner | last post by:
No you don't need to know Zope to help me. The whole reason I'd even want to do this is because of Zope though. I made a Zope product, and now want to perfect it. some simple example code... ...
9
by: starbuck | last post by:
Hi, have a form, with a text input "fieldname". method POST $var = $_POST $var is then used to search in mysql select * from table where jobtype like '$var%'
2
by: TS | last post by:
In these 2 snippets, "user" references 2 different things in my app: ------------------------------------------------- Dim ident As System.Security.Principal.WindowsIdentity =...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
14
by: rodchar | last post by:
hey all, i have a winapp that imports a text file into a typed dataset using the data adapter. some of the values are null. is there a way to remove the null values and put an empty string for...
0
by: Mike Wasilewski | last post by:
I am trying to get file information using COM but I do not get all of the info using the code below. $shell = new COM("Shell.Application") or die("COM Shell Application Problem."); $myfolder=...
8
by: Robert Dufour | last post by:
I have a winforms project Vs2005 with one project - Project1 which is the startup project and clsProject2 which is a class that is being used by Project1 (an exception handler). In clsProject2 I...
13
by: frk.won | last post by:
I am interested in learning how to use the VS 2005 code snippets. However, I wish to know what are the best ways to source control the code snippets? Are there any source safe/subversion...
4
by: tshad | last post by:
I was watching a video that used a code snippet to create a property and when you type "prop" tab tab, it would create the private variable as well as the property definitions with the private...
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,...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.