GetIP获取IP地址

import java.net.*;
public class GetIP
{
public static void main(String args[])
{
InetAddress sina = null;
InetAddress myIP = null;
InetAddress []yahoo=null;
try
{
//使用getByName获得sina的IP地址
sina = InetAddress.getByName(“www.sina.com.cn”);
//获得本机地址
myIP = InetAddress.getLocalHost();
//使用getAllByName获得yahoo的地址数组
yahoo=InetAddress.getAllByName(“www.yahoo.com.cn”);
}
catch(UnknownHostException e)
{
e.printStackTrace();
}
System.out.println(sina);
System.out.println(myIP);
for(int i=0;i<yahoo.length;i++)
System.out.println(yahoo[i]);
}
}

发布了48 篇原创文章 · 获赞 3 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/chscomfaner/article/details/82702638