Path: blob/master/test/jdk/java/net/NetworkInterface/NetParamsTest.java
41149 views
/*1* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 469193225* @summary Programmatic access to network parameters26*/2728import java.net.*;29import java.util.Enumeration;3031public class NetParamsTest {32private static void printIF(NetworkInterface netif) throws SocketException {33System.out.println(netif.getName() + " : ");34System.out.println("\tStatus: " + (netif.isUp() ? " UP" : "DOWN"));35byte[] mac = netif.getHardwareAddress();36if (mac != null) {37System.out.print("\tHardware Address: ");38for (byte b : mac) {39System.out.print(Integer.toHexString(b) + ":");40}41System.out.println();42}43System.out.println("\tLoopback: " + netif.isLoopback());44System.out.println("\tPoint to Point: " + netif.isPointToPoint());45System.out.println("\tVirtual: " + netif.isVirtual());46if (netif.isVirtual()) {47NetworkInterface parent = netif.getParent();48String parentName = parent == null ? "null" : parent.getName();49System.out.println("\tParent Interface: " + parentName);50}51System.out.println("\tMulticast: " + netif.supportsMulticast());5253System.out.println("\tMTU: " + netif.getMTU());54System.out.println("\tBindings:");55java.util.List<InterfaceAddress> binds = netif.getInterfaceAddresses();56for (InterfaceAddress b : binds) {57System.out.println("\t\t" + b);58}59Enumeration<NetworkInterface> ifs = netif.getSubInterfaces();60while(ifs.hasMoreElements()) {61NetworkInterface subif = ifs.nextElement();62printIF(subif);63}64}6566public static void main(String[] args) throws Exception {67Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();68while (ifs.hasMoreElements()) {69NetworkInterface netif = ifs.nextElement();70printIF(netif);71}72}73}747576