• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get local real address?

 
Li Dongfeng
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i get the local address?If i use InetAddress.getLocalHost() method,it only returns the local inner address,but i want to get the outer and the real address on the internet.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about getHostName or getCanonicalHostName?
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, from the title, I would have thought you meant "memory address", but it seems plain your' looking for your computer's IP address.
There's a problem here. A computer can have multiple IP addresses - as do two of the servers in my setup. One of them is a gateway, so it has not only multiple IP addresses, but not all of them are on the same network segment!
Also, a desktop machine's "Internet IP address" may not technically exist. When you're working with the common setup of having DHCP-assigned desktops with NAT, the apparent address to the rest of the world is not the same as your address to the local LAN.
These are some of the reasons why it's usually preferable to refer to hosts by name. The name is usually attributable to some specific service and remains relatively constant, but the IP addresses are much more volatile.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!