public static boolean isLocalAddress(Socket socket) throws UnknownHostException {
  InetAddress test=socket.getInetAddress();
  if (test.isLoopbackAddress()) {
    return true;
  }
  InetAddress localhost=InetAddress.getLocalHost();
  String host=localhost.getHostAddress();
  for (  InetAddress addr : InetAddress.getAllByName(host)) {
    if (test.equals(addr)) {
      return true;
    }
  }
  return false;
}

public static boolean isLocalAddress ( Socket socket ) throws UnknownHostException { InetAddress test = socket . getInetAddress ( ) ; if ( test . isLoopbackAddress ( ) ) { return true ; } InetAddress localhost = InetAddress . getLocalHost ( ) ; String host = localhost . getHostAddress ( ) ; for ( InetAddress addr : InetAddress . getAllByName ( host ) ) { if ( test . equals ( addr ) ) { return true ; } } return false ; }
check if a socket is connected to a local address .
