Skip to content

Instantly share code, notes, and snippets.

@karellism
Created December 30, 2015 01:27
Show Gist options
  • Save karellism/29445e8e60a590ff2ad2 to your computer and use it in GitHub Desktop.
Save karellism/29445e8e60a590ff2ad2 to your computer and use it in GitHub Desktop.
LocalHostName.java
import java.net.InetAddress;
import java.net.UnknownHostException;
public class HostnameExample {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getLocalHost();
System.out.println("Hostname: " + address.getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment