TestHost.java
| 1 |
package test; |
|---|---|
| 2 |
|
| 3 |
import java.io.PrintStream; |
| 4 |
import java.net.InetAddress; |
| 5 |
import java.net.NetworkInterface; |
| 6 |
import java.util.HexFormat; |
| 7 |
|
| 8 |
public class TestHost |
| 9 |
{
|
| 10 |
|
| 11 |
public static void main(String[] args) |
| 12 |
{
|
| 13 |
int len = args.length;
|
| 14 |
if (len <= 0) |
| 15 |
{
|
| 16 |
System.out.println("Usage: java -cp . test.TestHost host1 [ host2 ...]"); |
| 17 |
return;
|
| 18 |
} |
| 19 |
PrintStream ps = new PrintStream(System.out, true); |
| 20 |
for (int i = 0; i < len; i++) |
| 21 |
{
|
| 22 |
try
|
| 23 |
{
|
| 24 |
String host = args[i];
|
| 25 |
ps.append("host = ").append(host).append("\r\n"); |
| 26 |
InetAddress addr = InetAddress.getByName(host); |
| 27 |
ps.append("addr = ")
|
| 28 |
.append(addr.toString()) |
| 29 |
.append(", loopback=")
|
| 30 |
.append(String.valueOf(addr.isLoopbackAddress()))
|
| 31 |
.append(", wildcard_address=")
|
| 32 |
.append(String.valueOf(addr.isAnyLocalAddress()))
|
| 33 |
.append("\r\n");
|
| 34 |
|
| 35 |
NetworkInterface nic = NetworkInterface.getByInetAddress(addr); |
| 36 |
ps.append("nic = ")
|
| 37 |
.append(nic.toString()) |
| 38 |
.append(", loopback=")
|
| 39 |
.append(String.valueOf(nic.isLoopback()))
|
| 40 |
.append(", virtual=")
|
| 41 |
.append(String.valueOf(nic.isVirtual()))
|
| 42 |
.append(", up=")
|
| 43 |
.append(String.valueOf(nic.isUp()))
|
| 44 |
.append(", mtu=")
|
| 45 |
.append(String.valueOf(nic.getMTU()))
|
| 46 |
.append(", had=")
|
| 47 |
.append(nic.getHardwareAddress() != null ? HexFormat.of().formatHex(nic.getHardwareAddress()) : null) |
| 48 |
.append("\r\n");
|
| 49 |
} |
| 50 |
catch(Throwable e) |
| 51 |
{
|
| 52 |
e.printStackTrace(ps); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
} |