Code example for InetAddress

Methods: getAddress

0
         * Look at the IP Address of the two hosts. Compare  
         * the 3rd octet. If they are the same then the hosts 
         * are in the same rack else different racks.  
        */ 
        byte[] ip = host.getAddress();
        byte[] ip2 = host2.getAddress();
 
        return ip[2] == ip2[2];
    } 
 
    public boolean isInSameDataCenter(InetAddress host, InetAddress host2) throws UnknownHostException
    { 
        /* 
         * Look at the IP Address of the two hosts. Compare  
         * the 2nd octet. If they are the same then the hosts 
         * are in the same datacenter else different datacenter.  
        */ 
        byte[] ip = host.getAddress();
        byte[] ip2 = host2.getAddress();
 
        return ip[1] == ip2[1];