1 New project, newly built a class
The program is very simple to analyze and use a function getAllByName ()
Enter the following code:
Import java.io. *; import java.net. *; ///// gethost.java///public class gethost {public static void main (string arg []) {if (arg.length> = 1 ) {Inetaddress [] inet; INT i = 1; try {for (i = 1; i <= arg.length; i ) {inet = inetaddress.getallbyName (arg [i-1]); for (int J = 1 J <= inet.length; j ) {system.out.print (inet [j-1] .tostring ()); system.out.print ("/ n");}}} catch (unknownhostexception e) { System.out.print ("Unknown Hostname!" Arg [i-1]);}}}} else {system.out.print ("USAGE JAVA / JVIEW Getip");}}}
2 At this point, select Project-> Project Propoties Enter the URL you want to query in the Application Parameters in the run in Tab, such as www.sohu.com, click Run, you can see the return IP address.
3 I am also debugging today, usually you only need to use the command line in JDK
Java gethost www.sohu.com is OK, but in JB
4 I will use JB's experience, one is to organize some information for beginners to learn, after all, this area is too small. I hope to have a master to make valuable advice to my experience, for my learning, thank you!