Skip to content

Instantly share code, notes, and snippets.

@alpercalisir
Created January 15, 2019 00:06
Show Gist options
  • Save alpercalisir/1cac38ae20bfcd7f74a1e692c3d97505 to your computer and use it in GitHub Desktop.
Save alpercalisir/1cac38ae20bfcd7f74a1e692c3d97505 to your computer and use it in GitHub Desktop.
import java.net.*;
public class IdentifyHostNameIP {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
try {
InetAddress address = InetAddress.getByName(args[i]);
System.out.print("Host name: " + address.getHostName() + " ");
System.out.println("IP address: " + address.getHostAddress());
}
catch (UnknownHostException ex) {
System.err.println("Unknown host or IP address " + args[i]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment