Java Network Interface Get getNetworkInterface()

Here you can find the source of getNetworkInterface()

Description

get Network Interface

License

Open Source License

Declaration

private static String getNetworkInterface() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

import java.net.NetworkInterface;

import java.net.SocketException;

import java.util.Enumeration;
import java.util.regex.Pattern;

public class Main {
    private static String getNetworkInterface() {

        String networkInterfaceName = ">>>> modify networkInterface in us.codecraft.webmagic.utils.ProxyUtils";
        Enumeration<NetworkInterface> enumeration = null;
        try {//from  ww  w . j  ava 2 s .  co  m
            enumeration = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e1) {
            e1.printStackTrace();
        }
        while (enumeration.hasMoreElements()) {
            NetworkInterface networkInterface = enumeration.nextElement();

            Enumeration<InetAddress> addr = networkInterface.getInetAddresses();
            while (addr.hasMoreElements()) {
                String s = addr.nextElement().getHostAddress();
                Pattern IPV4_PATTERN = Pattern
                        .compile("^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
                if (s != null && IPV4_PATTERN.matcher(s).matches()) {
                    networkInterfaceName += networkInterface.toString() + "IP:" + s + "\n\n";
                }
            }
        }
        return networkInterfaceName;
    }
}

Related

  1. getLoopbackInterfaceName()
  2. getLoopbackNIF()
  3. getMac()
  4. getMacBytes()
  5. getNetworkErrorMessage(Throwable e)
  6. getNetworkInterface()
  7. getNetworkInterface(String name)
  8. getNetworkInterfaceArray(String name)
  9. getNetworkinterfaceByName(String name)