Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.net.*;

import java.util.*;

public class Main {
    /** Finds a network interface of sub-interface with the given name */
    public static NetworkInterface getByName(String name) throws SocketException {
        if (name == null)
            return null;
        Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
        while (en.hasMoreElements()) {
            NetworkInterface intf = en.nextElement();
            if (intf.getName().equals(name))
                return intf;
            Enumeration<NetworkInterface> en2 = intf.getSubInterfaces();
            while (en2.hasMoreElements()) {
                NetworkInterface intf2 = en2.nextElement();
                if (intf2.getName().equals(name)) {
                    return intf2;
                }
            }
        }
        return null;
    }
}