Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active June 4, 2018 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/cbb3749caa9e96c619cf07875dda5bb5 to your computer and use it in GitHub Desktop.
Save thmain/cbb3749caa9e96c619cf07875dda5bb5 to your computer and use it in GitHub Desktop.
import java.net.InetAddress;
import java.net.UnknownHostException;
public class PrintIPAddress {
public static void getIPAddress(){
try {
//get the local host
InetAddress localHost = InetAddress.getLocalHost();
//get the ipaddress
String ipaddress = localHost.getHostAddress();
System.out.println("IP ADDRESS is : " + ipaddress);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
getIPAddress();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment