473,804 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ 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.ja vaEnabled() && (navigator.appN ame != "Microsoft Internet
Explorer")) {
vartool=java.aw t.Toolkit.getDe faultToolkit();
addr=java.net.I netAddress.getL ocalHost();
host=addr.getHo stName();
ip=addr.getHost Address();
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 7642
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.ja vaEnabled() && (navigator.appN ame != "Microsoft Internet
Explorer")) {
vartool=java.aw t.Toolkit.getDe faultToolkit();
addr=java.net.I netAddress.getL ocalHost();
host=addr.getHo stName();
ip=addr.getHost Address();
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********@atme dia.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.ja vaEnabled() && (navigator.appN ame != "Microsoft Internet
Explorer")) {
vartool=java.aw t.Toolkit.getDe faultToolkit();
addr=java.net.I netAddress.getL ocalHost();
host=addr.getHo stName();
ip=addr.getHost Address();
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.java Enabled() &&
(navigator.appN ame != "Microsoft Internet Explorer")) {
var tool = java.awt.Toolki t.getDefaultToo lkit();
var addr = java.net.InetAd dress.getLocalH ost();
var host = addr.getHostNam e();
var ip = addr.getHostAdd ress();
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*****@agrico reunited.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
1511
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... <code> class User: def View(self):
9
2318
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
2020
by: TS | last post by:
In these 2 snippets, "user" references 2 different things in my app: ------------------------------------------------- Dim ident As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent() Dim User As New System.Security.Principal.WindowsPrincipal(ident) & HttpContext.Current.User -------------------------------------------------
18
3165
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 question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the ASP.Net process is recycled? This code executes pretty frequently (maybe 4 times per transaction) and...
14
1278
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 character fields and 0 for numeric fields? is there a possible expression i can use in the typed dataset properties for each field to rid the nulls? thanks,
0
1223
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= $shell->Namespace(0); $fileinfo= $myfolder->ParseName("C:\\test.wma"); for ($i=0; $i<33; $i++) { echo $i.") ".$myfolder->GetDetailsOf("",$i).": ".$myfolder->GetDetailsOf($fileinfo,$i)."<br>";
8
1796
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 have a procedure that must take information from the app.config file of Project1. In the clsproject2 I need to write code that gets the value of a setting in the app.config file of Project1. I find that the code I had that seemed to work ijn Vs2003...
13
2332
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 add-ons for this purpose? If not, any urls which demonstrates code snippets management?
4
2198
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 variable in it. When you changed the private variable it would also change the variables in the Property definition. But when I do it, I only get the property definition but no variables in it: public int MyProperty { get; set; }
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.