473,387 Members | 3,801 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.

calculating client IP address

I want to create a link that a user can click which will create a popup
telling the user their ip address. I have:

var ip = new java.net.InetAddress.getLocalHost().toString();
alert("Your IP address is: " + ip.substring(ip.indexOf("/")+1))

but this does not seem to work. It says the ip is 127.0.0.1. Strangely,
this piece of code used to work but all of a sudden it doesn't for some
unknown reason. Can anyone tell me what's wrong with the above code?

Lowell
Jul 23 '05 #1
3 2031
Lowell Kirsh wrote on 21 aug 2004 in comp.lang.javascript:
I want to create a link that a user can click which will create a popup
telling the user their ip address. I have:
If it does not direct to a[nother] page it is not a link
var ip = new java.net.InetAddress.getLocalHost().toString();
alert("Your IP address is: " + ip.substring(ip.indexOf("/")+1))
What scriptlanguage/platform are you using ["new java.net"?]?
Surely not clientside javascript with DOM [=wisdom?] ?
but this does not seem to work. It says the ip is 127.0.0.1. Strangely,
this piece of code used to work but all of a sudden it doesn't for some
unknown reason. Can anyone tell me what's wrong with the above code?


We would first have to know the above.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
On 21 Aug 2004 07:41:23 GMT, Evertjan. <ex**************@interxnl.net>
wrote:
Lowell Kirsh wrote on 21 aug 2004 in comp.lang.javascript:


[snip]
var ip = new java.net.InetAddress.getLocalHost().toString();
alert("Your IP address is: " + ip.substring(ip.indexOf("/")+1))


What scriptlanguage/platform are you using ["new java.net"?]?
Surely not clientside javascript with DOM [=wisdom?] ?


It's Java (the networking package) being called from JavaScript. Opera and
IE don't seem to support that (if they do, a different syntax is required).
but this does not seem to work. It says the ip is 127.0.0.1. Strangely,
this piece of code used to work but all of a sudden it doesn't for some
unknown reason. Can anyone tell me what's wrong with the above code?


Whilst this would be more appropriate in a Java group, you're here now.

If you look at the description of the getLocalHost() method, you'll see:

If there is a security manager, its checkConnect method is called
with the local host name and -1 as its arguments to see if the
operation is allowed. If the operation is not allowed, an
InetAddress representing the loopback address is returned.

Java running under JavaScript will be using a security manager and, I
should imagine, a very restricted one at that. Whilst the code worked
running on my machine (using only Mozilla and Netscape, I might add), I
doubt that it will work from a remote host. In that case, as it states
above, you'll have the loopback address returned.

In other words: it a security thing that you can do nothing about.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
On Sat, 21 Aug 2004 08:14:10 GMT, Michael Winter wrote:
Java running under JavaScript will be using a security manager and, I
should imagine, a very restricted one at that.


Java run under the control of JS is actually subjected
to a more strict security environment than are regular
applets. Im afraid I have few further details, but am
amazed the OP could ever get any access to the user's IP
address using Java in an applet (let alone one operated
via JS) ..reaks of the MSVM to me..

If that is the case 'used to worki n IE', my only advice
to the OP is 'get used to *not* being able to do that'..

The MSVM is no longer supported by MS, and there are
various utilities on 'the market' for ridding one's
Windows of this insecure pretence for Java.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #4

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

Similar topics

1
by: StormyTheCat | last post by:
Perhaps this is easy, but I'm new to C# am in need of some help. I need to embed a CRC value into an XML file to be able to detect when the data contained therin is corrupted. Calculating the...
5
by: JezB | last post by:
Any way I can get at a unique "Client ID" within server code ? I'm writing some auditing and I want to record which particular client machine initiated a request, for example. I imagine in an...
4
by: Goh | last post by:
Hi, I would like to know how can we implement a web page that intelligent enough to unique identify that pc have been visit before without any cookies and login user require. I have try...
13
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
2
by: WhatHappend | last post by:
I have converted a .Net 1.0 application to .Net 2.0 and the web service invocations have delay of around 10seconds on each intial access. After the first access subsequent access are fast (After a...
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
9
by: cman | last post by:
What are the mechanics involved in the calculation of an offset of a structure member, demonstrated in this piece of code? #define list_entry(ptr, type, member) \ ((type *)((char...
8
by: FrobinRobin | last post by:
Hi, I intend to use Ajax for a kiosk application, it's primary usage is to retrieve live data from my DB, it's a fairly small amount of data (5 fields, of small data size and limited to 15...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
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.