Here you can find the source of isThisMyIpAddress(InetAddress addr)
Parameter | Description |
---|---|
addr | the address to be checked |
public static boolean isThisMyIpAddress(InetAddress addr)
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; public class Main { /**/* w w w .ja v a 2 s .c o m*/ * Check if the given address is pointing to this local machine. * * @param addr * the address to be checked * @return true if the address is pointing to the local machine, false * otherwise */ public static boolean isThisMyIpAddress(InetAddress addr) { /* check if the address is a valid special local or loop back */ if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return true; } /* check if the address is defined on any interface */ try { return NetworkInterface.getByInetAddress(addr) != null; } catch (SocketException ex) { return false; } } }