Skip to content

Instantly share code, notes, and snippets.

@dataf3l
Created December 15, 2015 15:22
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 dataf3l/e3fcfef54ad5e8a54fb3 to your computer and use it in GitHub Desktop.
Save dataf3l/e3fcfef54ad5e8a54fb3 to your computer and use it in GitHub Desktop.
import java.net.InetAddress;
import java.net.UnknownHostException;
class Inet {
public static void main(String args[]){
String hostname = "Unknown";
try
{
InetAddress addr;
addr = InetAddress.getLocalHost();
hostname = addr.getHostName();
System.out.println(hostname);
}
catch (UnknownHostException ex)
{
System.out.println("Hostname can not be resolved");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment