Files
corejava/corejava第10版/v2ch04/inetAddress/InetAddressTest.java
T
2019-05-22 19:31:49 +08:00

30 lines
761 B
Java

package inetAddress;
import java.io.*;
import java.net.*;
/**
* This program demonstrates the InetAddress class. Supply a host name as command-line argument, or
* run without command-line arguments to see the address of the local host.
* @version 1.02 2012-06-05
* @author Cay Horstmann
*/
public class InetAddressTest
{
public static void main(String[] args) throws IOException
{
if (args.length > 0)
{
String host = args[0];
InetAddress[] addresses = InetAddress.getAllByName(host);
for (InetAddress a : addresses)
System.out.println(a);
}
else
{
InetAddress localHostAddress = InetAddress.getLocalHost();
System.out.println(localHostAddress);
}
}
}