2
|
1 |
/*
|
|
2 |
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
* @bug 4691932
|
|
26 |
* @summary Programmatic access to network parameters
|
|
27 |
*/
|
|
28 |
|
|
29 |
import java.net.*;
|
|
30 |
import java.util.Enumeration;
|
|
31 |
|
|
32 |
public class NetParamsTest {
|
|
33 |
private static void printIF(NetworkInterface netif) throws SocketException {
|
|
34 |
System.out.println(netif.getName() + " : ");
|
|
35 |
System.out.println("\tStatus: " + (netif.isUp() ? " UP" : "DOWN"));
|
|
36 |
byte[] mac = netif.getHardwareAddress();
|
|
37 |
if (mac != null) {
|
|
38 |
System.out.print("\tHardware Address: ");
|
|
39 |
for (byte b : mac) {
|
|
40 |
System.out.print(Integer.toHexString(b) + ":");
|
|
41 |
}
|
|
42 |
System.out.println();
|
|
43 |
}
|
|
44 |
System.out.println("\tLoopback: " + netif.isLoopback());
|
|
45 |
System.out.println("\tPoint to Point: " + netif.isPointToPoint());
|
|
46 |
System.out.println("\tVirtual: " + netif.isVirtual());
|
|
47 |
if (netif.isVirtual()) {
|
|
48 |
System.out.println("\tParent Interface: " + netif.getParent().getName());
|
|
49 |
}
|
|
50 |
System.out.println("\tMulticast: " + netif.supportsMulticast());
|
|
51 |
|
|
52 |
System.out.println("\tMTU: " + netif.getMTU());
|
|
53 |
System.out.println("\tBindings:");
|
|
54 |
java.util.List<InterfaceAddress> binds = netif.getInterfaceAddresses();
|
|
55 |
for (InterfaceAddress b : binds) {
|
|
56 |
System.out.println("\t\t" + b);
|
|
57 |
}
|
|
58 |
Enumeration<NetworkInterface> ifs = netif.getSubInterfaces();
|
|
59 |
while(ifs.hasMoreElements()) {
|
|
60 |
NetworkInterface subif = ifs.nextElement();
|
|
61 |
printIF(subif);
|
|
62 |
}
|
|
63 |
}
|
|
64 |
|
|
65 |
public static void main(String[] args) throws Exception {
|
|
66 |
Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();
|
|
67 |
while (ifs.hasMoreElements()) {
|
|
68 |
NetworkInterface netif = ifs.nextElement();
|
|
69 |
printIF(netif);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
}
|