Beispiel #1
0
def main(ip_address, subnet_mask):
    """
    Validates the Ip and mask passed in
    """
    error = 400
    if utils.is_valid_ipv6(ip_address):
        try:
            if int(subnet_mask) < 129:
                return ipv6_subnet_calc(ip_address, subnet_mask)
            else:
                print("Invalid Subnet Mask")
        except ValueError:
            print("Invalid Subnet Mask")
    elif utils.is_valid_ip(ip_address):
        if utils.is_valid_subnet_mask(subnet_mask):
            return ipv4_subnet_calc(ip_address, subnet_mask, False)

        try:
            if int(subnet_mask) < 32 and int(subnet_mask) > 0:
                return ipv4_subnet_calc(ip_address, subnet_mask, True)
            else:
                print("Invalid Subnet Mask")
        except ValueError:
            print("Invalid Subnet Mask")
    return error
Beispiel #2
0
 def testInvalidSubnetMask(self):
     result = utils.is_valid_subnet_mask('0.255.255.192')
     self.assertFalse(result)
Beispiel #3
0
 def testInvalidSubnetMaskSlot4(self):
     result = utils.is_valid_subnet_mask('255.255.255.300')
     self.assertFalse(result)
Beispiel #4
0
 def testValidSubnetMaskSlot4(self):
     result = utils.is_valid_subnet_mask('255.255.255.192')
     self.assertTrue(result)
Beispiel #5
0
 def testValidSubnetMaskSlot1(self):
     result = utils.is_valid_subnet_mask('192.0.0.0')
     self.assertTrue(result)