Article Figure 1 Figure 2 Listing 1 Listing 2
Listing 3 Listing 4 Listing 5 sep2006.tar

Listing 3 myIpaddress method

public byte[] myIPAddress(int networkInterfaceID)
{

    /*  Verify that we obtained a valid networkInterfaceID */
    if (networkInterfaceID < 0 || devices.length <= networkInterfaceID)
        return null;

    /*  Set device to the network interface specified by the 
        networkInterfaceID */

    NetworkInterface device = devices[networkInterfaceID];

    /*  Get the array of IP addresses assigned to the network interface 
        specified by the networkInterfaceID */

NetworkInterfaceAddress[] addresses = devices[networkInterfaceID].addresses;

    /*  Network interfaces can have multiple IP addresses assigned to them 
        but in this example we are only grabbing the first address.  */

InetAddress address = addresses[0].address;

    /*  Convert the IP address to an array of bytes and return it to 
        the method that called this function */

    byte[] returnByte = address.getAddress();
    return returnByte;
}