• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Way to get IP address through Java?

 
William Ross
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, is there a way to obtain an IP address of the current box through using Java? I am creating an installation package and require the user type in their IP address. I would like the default adr in the box to be the IP of the current machine. Thanks in advance.
 
Carl Trusiak
Sheriff
Posts: 3341
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear in mind that the IP address is not an attribute of the computer, it's an attribute of the network adapter. So if a computer has two network adapters (it's quite common these days to have an adapter where you plug an Ethernet cable in as well as a wireless adapter), then it has two IP addresses.

Also bear in mind that the IP address can vary over time. When I'm at work my laptop is assigned an IP address by the office's server, and when I take the laptop home, it's assigned a different IP address by my ISP's server.
[ August 15, 2006: Message edited by: Paul Clapham ]
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how do you retrieve the external IP on a machine ?
I have 2 IPs, one internal to my home network, and one external, the one that i get on the internet.

Check this schema to see what i mean if it's not clear :
http://forum.portforward.com/YaBB.cgi?board=Knowledge;action=display;num=1116983138

// This retrieves the internal IP address but I want the external IP address
yourAddress=java.net.InetAddress.getLocalHost();

// Maybe something like that ??
netif = java.net.NetworkInterface.getByName("NameOfAMachineWithJVM");

Thanks in advance for your help
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that by "external IP address" you mean the IP address of the router or proxy server through which you are connected to the Internet. If you wanted, you could make an HTTP connection to http://whatismyipaddress.com/ and parse it out of the page you get back. At any rate, go to that page and read the FAQs. See if any of them help you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic