Two Laptop Bag
The moose likes Beginning Java and the fly likes My IP address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "My IP address" Watch "My IP address" New topic

My IP address

Dave Jones
Ranch Hand

Joined: Feb 20, 2005
Posts: 77
I'm writing a program and I need to get my IP address (i.e )
I tryed using this code,

but I get: as my address.....not very helpful eh ?...
does someone have a short code sample that will give me what I need ??
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
You're getting exactly what you're asking for, the local host which is always

Dave Jones
Ranch Hand

Joined: Feb 20, 2005
Posts: 77
I know, but I need the real ip address not !!
never mind, I got it already.
thanks anyway :roll:
Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
u got it???

tell me how??? even i need to know it
Abhishek Roy

Joined: Feb 07, 2003
Posts: 4
This may helpful

Run as (for IPv4)$java lookupAndReturn
OR as (for IPv6)$java -6 lookupAndReturn

[ March 17, 2005: Message edited by: Abhishek Roy ]
I agree. Here's the link:
subject: My IP address
It's not a secret anymore!