com.esf.util.net.service
Interface INetworkUtilityService


public interface INetworkUtilityService

Utilities to check the status of a network link


Field Summary
static java.lang.String SERVICE_NAME
          service name of this interface for the bundle activator (com.esf.util.net.service)
 
Method Summary
 java.lang.String calculateBroadcast(java.lang.String ipAddress, java.lang.String netmask)
          calculates the broadcast based on an IP address and subnet mask
 java.lang.String calculateNetwork(java.lang.String ipAddress, java.lang.String netmask)
          calculates the network based on an IP address and subnet mask
 boolean canPing(java.lang.String ipAddress, int count)
          pings a peer address a number of times.
 java.lang.String[] getAllInterfaceNames()
          gets the interface names as would be shown by the output of ifconfig -a
 java.lang.String getBroadcastAddress(java.lang.String ifaceName)
          gets the broadcast address for a specified interface.
 INetworkInterface getIface(java.lang.String name)
          gets the interface with the supplied name
 java.lang.String[] getInterfaceNames()
          gets the interface names as would be shown by the output of ifconfig
 java.lang.String getIpAddress(java.lang.String ifaceName)
          gets the IP address for a specified interface.
 java.lang.String getMacAddress(java.lang.String ifaceName)
          gets the MAC address for a specified interface.
 java.lang.String getNetmask(java.lang.String ifaceName)
          gets the netmask for a specified interface.
 int getNetmaskIntForm(java.lang.String netmask)
          gets the integer representation of the netmask (i.e.
 boolean isLinkUp(java.lang.String ifaceName)
          checks to see if a valid link is present
 boolean isUp(java.lang.String ifaceName)
          checks to see if an interface is 'up'
 

Field Detail

SERVICE_NAME

static final java.lang.String SERVICE_NAME
service name of this interface for the bundle activator (com.esf.util.net.service)

Method Detail

getInterfaceNames

java.lang.String[] getInterfaceNames()
gets the interface names as would be shown by the output of ifconfig

Returns:
the interfaces names currently 'up'

getAllInterfaceNames

java.lang.String[] getAllInterfaceNames()
gets the interface names as would be shown by the output of ifconfig -a

Returns:
the names of all interfaces regardless of 'up' status

isUp

boolean isUp(java.lang.String ifaceName)
checks to see if an interface is 'up'

Parameters:
ifaceName - the interface to check
Returns:
true if the interface is up, otherwise false

getIpAddress

java.lang.String getIpAddress(java.lang.String ifaceName)
gets the IP address for a specified interface. In order for this to return a valid response the interface must be up

Parameters:
ifaceName - the interface to get the IP address of
Returns:
a String representing the IP address of the specified interface. null is returned if the interface is not up

getNetmask

java.lang.String getNetmask(java.lang.String ifaceName)
gets the netmask for a specified interface. In order for this to return a valid response the interface must be up

Parameters:
ifaceName - the interface to get the netmask of
Returns:
a String representing the netmask of the specified interface. null is returned if the interface is not up

getBroadcastAddress

java.lang.String getBroadcastAddress(java.lang.String ifaceName)
gets the broadcast address for a specified interface. In order for this to return a valid response the interface must be up

Parameters:
ifaceName - the interface to get the broadcast address of
Returns:
a String representing the broadcast address of the specified interface. null is returned if the interface is not up

isLinkUp

boolean isLinkUp(java.lang.String ifaceName)
checks to see if a valid link is present

Parameters:
ifaceName - the interface to check
Returns:
true if a link is present, otherwise false

getMacAddress

java.lang.String getMacAddress(java.lang.String ifaceName)
gets the MAC address for a specified interface. In order for this to return a valid response the interface must be up

Parameters:
ifaceName - the interface to get the MAC address of
Returns:
a String representing the MAC address of the specified interface. null is returned if the interface is not up

calculateNetwork

java.lang.String calculateNetwork(java.lang.String ipAddress,
                                  java.lang.String netmask)
calculates the network based on an IP address and subnet mask

Parameters:
ipAddress - the IP address to use as a base for the calculation
netmask - the network mask to use as a base for the calculation
Returns:
the calculated network as a String

calculateBroadcast

java.lang.String calculateBroadcast(java.lang.String ipAddress,
                                    java.lang.String netmask)
calculates the broadcast based on an IP address and subnet mask

Parameters:
ipAddress - the IP address to use as a base for the calculation
netmask - the network mask to use as a base for the calculation
Returns:
the calculated broadcast address as a String

getNetmaskIntForm

int getNetmaskIntForm(java.lang.String netmask)
                      throws java.lang.Exception
gets the integer representation of the netmask (i.e. 8 for 255.0.0.0 and 16 for 255.255.0.0)

Parameters:
netmask - the netmask to convert it 'dotted notation' (i.e. 255.255.255.0)
Returns:
the integer representing the subnet mask
Throws:
java.lang.Exception - if the passed in subnet mask is invalid

canPing

boolean canPing(java.lang.String ipAddress,
                int count)
pings a peer address a number of times. The number of times is specified by the count. This method will return true if at least one ping response is detected.

Parameters:
ipAddress - the IP Address to ping
count - the number of times to try to ping the peer
Returns:
true if at least one ping response is returned, otherwise false

getIface

INetworkInterface getIface(java.lang.String name)
gets the interface with the supplied name

Parameters:
ifaceName - the interface to get
Returns:
An INetworkInterface Object representing the interface