How to get IP Address in Java ?

Sample Java Code to get IP Address

- no title specified- no title specified

import java.net.InetAddress;

import java.net.UnknownHostException;

public class GetIPAddress {

public static void main(String[] args) {

try {

InetAddress address = InetAddress.getLocalHost();

System.out.println("IP Address is:"+ address.getHostAddress());

} catch (UnknownHostException e) {

e.printStackTrace();

}

}

}

No comments:

Post a Comment