The example in this article describes Java's approach to obtaining domain name IP addresses. Share to everyone for your reference. as follows:
Import java.net.InetAddress;
Import java.net.UnknownHostException;
public class Testinetaddress {inetaddress myipaddress = null;
inetaddress[] MyServer = null;
public static void Main (String args[]) {testinetaddress address = new testinetaddress ();
System.out.println ("Your host IP is:" + address.getlocalhostip ());
String domain = www.jb51.net;
SYSTEM.OUT.PRINTLN ("The server domain name is:" + domain);
inetaddress[] array = address.getserverip (domain);
int count=0;
for (int i=1; i<array.length; i++) {System.out.println ("IP" + i + "" + address.getserverip (domain) [i-1]);
count++;
} System.out.println ("IP address total:" +count);} /** * get localhost IP address * @return/public inetaddress Getlocalhostip () {try {myipaddress = Inetaddress.getlocalhost ()
;
catch (Unknownhostexception e) {e.printstacktrace ();} return (myipaddress); /** * Obtain a domain name IP address * @param domain domain name * @return/public inetaddress[] Getserverip (String domain) {try {myServer = Inet
Address.getallbyname (domain); }catch (Unknownhostexception e) {e.printstacktrace ();} return (MyServer);
}
}
I hope this article will help you with your Java programming.