首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

依据主机字符串获得ip

2012-07-15 
根据主机字符串获得ipimport java.io.BufferedReaderimport java.io.IOExceptionimport java.io.InputSt

根据主机字符串获得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);}}}

热点排行