Here you can find the source of isLocalAddress(InetAddress addr)
Parameter | Description |
---|---|
addr | address to check if it is local node's address |
public static boolean isLocalAddress(InetAddress addr)
//package com.java2s; // Licensed to the Apache Software Foundation (ASF) under one import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; public class Main { /**/* w ww . j av a 2 s . co m*/ * Given an InetAddress, checks to see if the address is a local address, by * comparing the address with all the interfaces on the node. * @param addr address to check if it is local node's address * @return true if the address corresponds to the local node */ public static boolean isLocalAddress(InetAddress addr) { // Check if the address is any local or loopback. boolean local = addr.isAnyLocalAddress() || addr.isLoopbackAddress(); // Check if the address is defined on any interface. if (!local) { try { local = NetworkInterface.getByInetAddress(addr) != null; } catch (SocketException e) { // Pass. } } return local; } }