Skip to content

Instantly share code, notes, and snippets.

@yashk
Last active March 24, 2016 12:41
Show Gist options
  • Save yashk/10340702 to your computer and use it in GitHub Desktop.
Save yashk/10340702 to your computer and use it in GitHub Desktop.
import java.net.InetAddress;
import java.net.UnknownHostException;
public class dns {
public static void main(String[] args) throws UnknownHostException { InetAddress addr = InetAddress.getLocalHost();
System.out.println(
String.format(
"IP:%s hostname:%s canonicalName:%s",
addr.getHostAddress(), // The "default" IP address
addr.getHostName(), // The hostname (from gethostname())
addr.getCanonicalHostName() // The canonicalized hostname (from resolver)
));
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment