Java Network Interface Get getNetworkinterfaceByName(String name)

Here you can find the source of getNetworkinterfaceByName(String name)

Description

get Networkinterface By Name

License

Open Source License

Declaration

public static NetworkInterface getNetworkinterfaceByName(String name) throws SocketException 

Method Source Code

//package com.java2s;
/*/*w w w .j ava  2s .  c o m*/
 * Copyright (C) 2016 Alexander Christian <alex(at)root1.de>. All rights reserved.
 * 
 * This file is part of KONNEKTING Suite.
 *
 *   KONNEKTING Suite is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   KONNEKTING Suite is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with KONNEKTING DeviceConfig.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Main {
    public static NetworkInterface getNetworkinterfaceByName(String name) throws SocketException {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface ni = networkInterfaces.nextElement();
            if (ni.getName().equals(name)) {
                return ni;
            }
        }
        throw new SocketException("Interface with name '" + name + "' not found.");
    }
}

Related

  1. getNetworkErrorMessage(Throwable e)
  2. getNetworkInterface()
  3. getNetworkInterface()
  4. getNetworkInterface(String name)
  5. getNetworkInterfaceArray(String name)
  6. getNetworkInterfaceInfo(NetworkInterface pNif)
  7. getNetworkInterfaces( Predicate predicate)
  8. getNetworkInterfaces()
  9. getNetworkInterfaces()