Java Network Interface Check describeInterface(NetworkInterface subIf, boolean subinterface)

Here you can find the source of describeInterface(NetworkInterface subIf, boolean subinterface)

Description

describe Interface

License

Apache License

Declaration

public static String describeInterface(NetworkInterface subIf, boolean subinterface) throws SocketException 

Method Source Code

//package com.java2s;
/*/*from w w  w .j  a  va  2s. com*/
 * Copyright 2016 tamas.csaba@gmail.com.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.net.InetAddress;

import java.net.NetworkInterface;

import java.net.SocketException;

import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;

public class Main {
    public static String describeInterface(NetworkInterface subIf, boolean subinterface) throws SocketException {
        StringBuilder description = new StringBuilder();
        String padding = "";
        if (subinterface) {
            description.append("\t\tSUBINTERFACE");
            description.append("\t\t____________");
            padding = "\t\t";
        }
        description.append(String.format("%sInterface Display name: %s\n", padding, subIf.getDisplayName()));
        description.append(String.format("%sInterface Name: %s\n", padding, subIf.getName()));
        Enumeration<InetAddress> inetAddresses = subIf.getInetAddresses();
        for (InetAddress inetAddress : Collections.list(inetAddresses)) {
            description.append(String.format("%s\tInetAddress: %s\n", padding, inetAddress));
        }
        description.append(String.format("%s\t\tUp? %s\n", padding, subIf.isUp()));
        description.append(String.format("%s\t\tLoopback? %s\n", padding, subIf.isLoopback()));
        description.append(String.format("%s\t\tPointToPoint? %s\n", padding, subIf.isPointToPoint()));
        description.append(String.format("%s\t\tSupports multicast? %s\n", padding, subIf.supportsMulticast()));
        description.append(String.format("%s\t\tVirtual? %s\n", padding, subIf.isVirtual()));
        description.append(String.format("%s\t\tHardware address: %s\n", padding,
                Arrays.toString(subIf.getHardwareAddress())));
        description.append(String.format("%s\t\tMTU: %s\n", padding, subIf.getMTU()));
        description.append("\n");
        return description.toString();
    }
}

Related

  1. addAllInterfaces(List target, List level)
  2. checkMethod(NetworkInterface iface, Method toCheck)
  3. cloneInterfaces( List interfaces)
  4. dumpLocalNetworkInfo()
  5. hasNetworkAccess()
  6. isCIDR(String network)
  7. isHostInNetworkCard(String host)