Here you can find the source of isLocal(final String hostName)
Parameter | Description |
---|---|
hostName | host name |
public static boolean isLocal(final String hostName)
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; public class Main { /**//from w ww.j ava 2 s. c o m * Checks if given host name is local. * * @param hostName host name * @return {@code true} if host name pointing to local address */ public static boolean isLocal(final String hostName) { try { return isLocal(InetAddress.getByName(hostName)); } catch (final UnknownHostException e) { return false; } } /** * Check if given address is local. * * @param address address * @return {@code true} if address is local */ public static boolean isLocal(final InetAddress address) { // Check if the address is a valid special local or loop back if (address.isAnyLocalAddress() || address.isLoopbackAddress()) { return true; } // Check if the address is defined on any interface try { return NetworkInterface.getByInetAddress(address) != null; } catch (final SocketException e) { return false; } } }