Java Local Address Get getLocalAddress(String adaptorName)

Here you can find the source of getLocalAddress(String adaptorName)

Description

get Local Address

License

Apache License

Declaration

private static InetAddress getLocalAddress(String adaptorName) 

Method Source Code

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

import java.net.*;

import java.util.Enumeration;

public class Main {
    private static InetAddress getLocalAddress(String adaptorName) {
        try {/*  ww  w.j  av  a  2  s  . c o m*/
            Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces();
            while (b.hasMoreElements()) {
                NetworkInterface networkInterface = b.nextElement();
                if (networkInterface.getName().equals(adaptorName)) {
                    for (InterfaceAddress f : networkInterface.getInterfaceAddresses()) {
                        if (f.getAddress().isSiteLocalAddress()) {
                            return f.getAddress();
                        }
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getLocalAddress()
  2. getLocalAddress(final String start, final String end)
  3. getLocalAddress(int port)
  4. getLocalAddress(int port)
  5. getLocalAddress(int port)
  6. getLocalAddress(String filter)
  7. getLocalAddress0()
  8. getLocalAddressAsString()
  9. getLocalAddresses()