org.littleshoot.proxy
Class NetworkUtils

java.lang.Object
  extended by org.littleshoot.proxy.NetworkUtils

public class NetworkUtils
extends Object

Network utilities methods.


Constructor Summary
NetworkUtils()
           
 
Method Summary
static InetAddress getLocalHost()
          Many Linux systems typically return 127.0.0.1 as the localhost address instead of the address assigned on the local network.
static Collection<InetAddress> getNetworkInterfaces()
          Utility method for accessing public interfaces.
static boolean isPublicAddress()
          Returns whether or not this host is on the public Internet.
static boolean isPublicAddress(InetAddress ia)
          Returns whether or not the specified address represents an address on the public Internet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkUtils

public NetworkUtils()
Method Detail

getLocalHost

public static InetAddress getLocalHost()
                                throws UnknownHostException
Many Linux systems typically return 127.0.0.1 as the localhost address instead of the address assigned on the local network. It has to do with how localhost is defined in /etc/hosts. This method creates a quick UDP socket and gets the local address for the socket on Linux systems to get around the problem.

Returns:
The local network address in a cross-platform manner.
Throws:
UnknownHostException - If the host is considered unknown for any reason.

isPublicAddress

public static boolean isPublicAddress(InetAddress ia)
Returns whether or not the specified address represents an address on the public Internet.

Parameters:
ia - The address to check.
Returns:
true if the address is an address on the public Internet, otherwise false.

isPublicAddress

public static boolean isPublicAddress()
Returns whether or not this host is on the public Internet.

Returns:
true if this host is on the public Internet, otherwise false.

getNetworkInterfaces

public static Collection<InetAddress> getNetworkInterfaces()
                                                    throws SocketException
Utility method for accessing public interfaces.

Returns:
The Collection of public interfaces.
Throws:
SocketException - If there's a socket error accessing the interfaces.


Copyright © 2009-2013 LittleShoot. All Rights Reserved.