Getting the client IP address

B

bruce_phipps

Is there a Java method I can use to retrieve the IP address of a Linux
computer on which is running my standalone client app?

On a related point, is there a Unix/Linux system environment variable
for IP address? The ifconfig command returns the IP address, amongst
other info.

Thanks
Bruce
 
K

Kai Schwebke

Is there a Java method I can use to retrieve the IP address of a Linux
computer on which is running my standalone client app?

Not "the IP address", but with
java.net.NetworkInterface.getNetworkInterfaces() you get
the interfaces of the box, which in turn
can be queried for their ip addresses.

Kai
 
B

bruce_phipps

Kai said:
Not "the IP address", but with
java.net.NetworkInterface.getNetworkInterfaces() you get
the interfaces of the box, which in turn
can be queried for their ip addresses.

Kai

I found this on the web. It seems to work do what I need:

InetAddress local = InetAddress.getLocalHost();

// Print address
System.out.println ("Local IP : " + local.getHostAddress());

Bruce
 
S

senior

(e-mail address removed) ÃÑÓáÊ:
Is there a Java method I can use to retrieve the IP address of a Linux
computer on which is running my standalone client app?

On a related point, is there a Unix/Linux system environment variable
for IP address? The ifconfig command returns the IP address, amongst
other info.

Thanks
Bruce

if you using socket in your network application

you can get the ip address for every body connect to your server by
getInetAddress in Socket class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top