473,387 Members | 1,579 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,387 software developers and data experts.

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 7620
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.