Win a copy of liveProject: Build an ML Recommender System this week in the Artificial Intelligence and Machine Learning 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

api to remote internet IP and local IP address of my computer

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a standalone java application, how can I get remote internet IP address and local IP address of my computer ?

DHCP will assign an internet IP to me when I am using internet. Which API I can access that IP address ? On the other side, how can I get my local IP, like 192.168.0.1... ?

Thanks.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edward,

What you're calling the "local IP address" is probably the LAN address; that's actually the address that you're assigned by DHCP. It's the "real" address of the machine on the local network. You're probably using a NAT setup, which stands for "Network Address Translation;" this is the widely used system by which many machines on a LAN can share a single Internet address. Your computer does not actually know what that Internet address is -- the network packets are modified by the NAT box (i.e., a router attached to your LAN) for transmittal to the Internet. There's no API by which your local machine can find out what that address is.

You can get your LAN address with InetAddress.getLocalHost().getHostAddress() .
 
Sheriff
Posts: 22157
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The WAN address (the official term for your Internet IP address) is only available through external resources. There are several websites that give you back your IP address, you can find several using what's my ip. You will need to parse the results though.
 
a wee bit from the empire
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic