Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
Import java.net. inetaddress; import java.net. unknownhostexception; import Java. io. ioexception; public class showip {public static void main (string Arg []) {inetaddress address; try {address = inetaddress. getbyname ("g.cn"); showaddress (Address); Address = inetaddress. getlocalhost (); showaddress (Address); byte A [] = {127,0, 0, 1}; address = inetaddress. getbyaddress (a); showaddress (Address);} catch (unknownhostexception e) {system. out. println (e) ;}} static void showaddress (inetaddress Address) {byte A [] = address. getaddress (); system. out. println (address. gethostname () + ":" + (A [0] & 0xff) + ". "+ (A [1] & 0xff) + ". "+ (A [2] & 0xff) + ". "+ (A [3] & 0xff); // With 0xff, remove the IF (address. isloopbackaddress () system. out. println ("(the loopback address)"); try {If (address. isreachable (30000) system. out. println ("(is reachable)");} catch (ioexception e ){}}}
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/