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("");
}
}
}
catch(unknownhostexception e){
system.out.print("unknown hostname!"+arg[i-1]);
}
}
else{
system.out.print("usage java/jview getip <hostname>");
}
}
}
</pre>
</p>
<p>
<pre>
<font color=red>example 2</font>
<a href="gethtml.java">download now</a>
//gethtml.java
/**
* this is a program which can read information from a web server.
* @version 1.0 2000/01/01
* @author jdeveloper
**/
import java.net.*;
import java.io.*;
public class gethtml {
public static void main(string args[]){
if (args.length < 1){
system.out.println("usage: java gethtml httpaddress");
system.exit(1);
}
string surladdress = new string(args[0]);
url url = null;
try{
url = new url(surladdress);
}catch(malformedurlexception e){
system.err.println(e.tostring());
system.exit(1);
}
try{
inputstream ins = url.openstream();
bufferedreader breader = new bufferedreader(new inputstreamreader(ins));
string info = breader.readline();
while(info != null){
system.out.println(info);
info = breader.readline();
}
}
catch(ioexception e){
system.err.println(e.tostring());
system.exit(1);
}
}
}
闽公网安备 35060202000074号