Example command window:
C:\ece538\javafx_PP\ch31>java IdentifyHostNameIP udayton.edu Host name: udayton.edu IP address: 131.238.72.77 C:\ece538\javafx_PP\ch31>java IdentifyHostNameIP johnloomis.org Host name: johnloomis.org IP address: 50.63.90.1 C:\ece538\javafx_PP\ch31>java IdentifyHostNameIP localhost Host name: localhost IP address: 127.0.0.1
IdentifyHostNameIP.java
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]); } } } }
Maintained by John Loomis, updated Mon Mar 26 11:52:14 2018