This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes How to get the real ip? (gateway ip instead of machine ip) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to get the real ip? (gateway ip instead of machine ip)" Watch "How to get the real ip? (gateway ip instead of machine ip)" New topic
Author

How to get the real ip? (gateway ip instead of machine ip)

Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
Hi,
I want to get my real ip because that ip is for server use (http://ip:8080/...), I tried:
InetAddress local = InetAddress.getLocalHost();
System.out.println(local.getHostAddress());
}catch (java.net.UnknownHostException e){}
But it gives me my machine ip instead of real ip, using http://machineip/... people can't reach my comp. So please would anyone know how can I get my real ip?Thanks!


Thanks everyone who helped me
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
I'd like to stick an "I don't know what I'm talking about" sticker on this reply.
Would it be possible for you to do something fancy like connect to another machine and have it tell you your IP address?
Maybe the dnsjava implementation can do it properly (something like "org.xbill.DNS.dns.inaddrString(InetAddress.getLocalHost())").
You could also try plain old InetAddress.getAddress() just in case it wants to be cool.
[ April 07, 2002: Message edited by: David Weitzman ]
Lewin Chan
Ranch Hand

Joined: Oct 10, 2001
Posts: 214
I guess the question you've asked is really :
How do I know what address I am presenting to the Internet, rather than my own machine IP.
If this is because you are, as people have mentioned, behind a firewall, and your machine IP is in a private addressing range (10.x.x.x, 192.168.x.x etc), and are using NAT to connect to the outside world through a router/firewall. The answer is you can't really do this programatically thru java...
What you can do is to setup ip filtering on your firewall/router such that all inbound packets from the internet to xyz.acme.com:8080 are passed to your machine.


I have no java certifications. This makes me a bad programmer. Ignore my post.
 
jQuery in Action, 2nd edition
 
subject: How to get the real ip? (gateway ip instead of machine ip)
 
Similar Threads
Getting the REAL ip address
Finding the IP Address of Remote Machines if any connected to my Current machine
DHCP server
Uploading Applet
How can i find out the ip address of the machine in Java