Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How to get local real address?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about getHostName or getCanonicalHostName?
 
Saloon Keeper
Posts: 23419
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
This tiny ad is wafer thin:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic