|
How to Detect IP Address and Name of Host machine without using Socket programming |
|
|
java.net.InetAddress Class has a static method getLocalHost method which returns Object of localHost Then GetHostAddress Method Returns the IP address string in textual presentation. So in Your program use following line to print IP Address.
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IPAdress {
public static void main(String[] args) {
try {
System.out.println(InetAddress.getLocalHost().getHostName());
System.out.println(InetAddress.getLocalHost().getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.