JAva解析ホスト名ipアドレス取得
728 ワード
import java.net.*;
/**
* ip
*/
public class GetIpByHostName {
public static void main(String[] args){
InetAddress address = null;
if(args.length == 0){
System.out.println("usage: getip host");
System.exit(1);
}
try{
address = InetAddress.getByName(args[0]);
}catch(Exception e){
System.out.println("not found");
System.exit(2);
}
System.out.println(address.getHostName() + "=" + address.getHostAddress());
System.exit(0);
}
}