GetIP obtain an IP address

* the java.net Import;.
public class Getip
{
public static void main (String args [])
{
InetAddress sina = null;
InetAddress myIP = null;
InetAddress [] Yahoo = null;
the try
{
// getByName using the IP address obtained sina
= InetAddress.getByName siNA ( "www.sina.com.cn");
// get the local address
myIP the InetAddress.getLocalHost = ();
// yahoo obtained using getAllByName address array
yahoo = InetAddress.getAllByName ( "www.yahoo . Com.cn ");
}
the 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]);
}
}

Published 48 original articles · won praise 3 · views 20000 +

Guess you like

Origin blog.csdn.net/chscomfaner/article/details/82702638