读书人

依据主机字符串获得ip

发布时间: 2012-07-15 20:11:39 作者: rapoo

根据主机字符串获得ip

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.InetAddress;/* * write by 1xiu  * 2011-12-23 * just for test * */public class getIP {/** * @param args * @throws IOException  */public static void main(String[] args) throws IOException {// TODO Auto-generated method stubString hostname;//输入BufferedReader input = new BufferedReader(new InputStreamReader(System.in));System.out.print("\n");System.out.print("Host name:");//读取输入的主机名hostname = input.readLine();try {InetAddress ipAddress = InetAddress.getByName(hostname);System.out.print("Ip :"+ipAddress.getHostAddress());} catch (Exception e) {// TODO: handle exceptionSystem.out.print("can not find the ip for:"+hostname);}}}

读书人网 >互联网

热点推荐