def test_ipaddr_empty_query(self):
        self.assertEqual(ipaddr.ipaddr("192.0.2.230"), "192.0.2.230")
        self.assertEqual(ipaddr.ipaddr("192.0.2.230/30"), "192.0.2.230/30")
        self.assertEqual(ipaddr.ipaddr([]), [])

        self.assertEqual(ipaddr.ipaddr(True), False)
        self.assertEqual(ipaddr.ipaddr(""), False)
def ipaddr_hash(value, seed):
    ''' takes a given IP prefix, and returns it combined with the sha256 sum
        of the seed to form a complete address. Works best with large prefixes
        (i.e., IPv6) due to the bigger address space. '''

    if netaddr is None:
        raise AnsibleFilterError(
                "The ipaddr_hash filter requires python's netaddr be "
                "installed on the ansible controller")

    try:
        vtype = ipaddr(value, 'type')
        if vtype == 'address':
            v = ipaddr(value, 'cidr')
        elif vtype == 'network':
            v = ipaddr(value, 'subnet')

        value = netaddr.IPNetwork(v)
    except Exception:
        raise AnsibleFilterError(
                "The ipaddr_hash filter requires a valid IPv6 prefix")

    if not seed:
        raise AnsibleFilterError(
                "The ipaddr_hash filter requires a non-empty seed, e.g., the "
                "inventory_hostname")

    dgst = hashlib.sha256(to_bytes(seed)).hexdigest()
    host = int(dgst, 16) & int(value.hostmask)
    net = int(value.ip) & int(value.netmask)
    ipver = ipaddr(value, 'version')
    return to_text(netaddr.IPAddress(net + host, ipver))
 def test_host_query(self):
     self.assertEqual(ipaddr.ipaddr("192.0.2.1", "host"), "192.0.2.1/32")
     address = "192.0.2.12/20"
     self.assertEqual(ipaddr.ipaddr(address, "host"), address)
     address = "192.0.2.0/31"
     self.assertEqual(ipaddr.ipaddr(address, "host"), address)
     self.assertIsNone(ipaddr.ipaddr("192.0.2.0/24", "host"))
Esempio n. 4
0
 def test_netmask(self):
     address = '1.1.1.1/24'
     self.assertEqual(ipaddr(address, 'netmask'), '255.255.255.0')
     address = '1.1.1.1/25'
     self.assertEqual(ipaddr(address, 'netmask'), '255.255.255.128')
     address = '1.12.1.34/32'
     self.assertEqual(ipaddr(address, 'netmask'), '255.255.255.255')
 def test_ipaddr_link_local_query(self):
     self.assertEqual(
         ipaddr.ipaddr("169.254.0.12", "link-local"), "169.254.0.12"
     )
     self.assertIsNone(ipaddr.ipaddr("192.0.2.12", "link-local"))
     self.assertEqual(ipaddr.ipaddr("fe80::9", "link-local"), "fe80::9")
     self.assertIsNone(ipaddr.ipaddr("2001::", "link-local"))
 def test_netmask(self):
     address = "1.1.1.1/24"
     self.assertEqual(ipaddr.ipaddr(address, "netmask"), "255.255.255.0")
     address = "1.1.1.1/25"
     self.assertEqual(ipaddr.ipaddr(address, "netmask"), "255.255.255.128")
     address = "1.12.1.34/32"
     self.assertEqual(ipaddr.ipaddr(address, "netmask"), "255.255.255.255")
 def test_broadcast(self):
     address = "1.12.1.34/24"
     self.assertEqual(ipaddr.ipaddr(address, "broadcast"), "1.12.1.255")
     address = "1.12.1.34/16"
     self.assertEqual(ipaddr.ipaddr(address, "broadcast"), "1.12.255.255")
     address = "1.12.1.34/27"
     self.assertEqual(ipaddr.ipaddr(address, "broadcast"), "1.12.1.63")
     address = "1.12.1.34/32"
     self.assertEqual(ipaddr.ipaddr(address, "broadcast"), None)
     address = "1.12.1.35/31"
     self.assertEqual(ipaddr.ipaddr(address, "broadcast"), None)
Esempio n. 8
0
 def test_broadcast(self):
     address = '1.12.1.34/24'
     self.assertEqual(ipaddr(address, 'broadcast'), '1.12.1.255')
     address = '1.12.1.34/16'
     self.assertEqual(ipaddr(address, 'broadcast'), '1.12.255.255')
     address = '1.12.1.34/27'
     self.assertEqual(ipaddr(address, 'broadcast'), '1.12.1.63')
     address = '1.12.1.34/32'
     self.assertEqual(ipaddr(address, 'broadcast'), None)
     address = '1.12.1.35/31'
     self.assertEqual(ipaddr(address, 'broadcast'), None)
 def test_network(self):
     address = "1.12.1.34/32"
     self.assertEqual(ipaddr.ipaddr(address, "network"), "1.12.1.34")
     address = "1.12.1.34/255.255.255.255"
     self.assertEqual(ipaddr.ipaddr(address, "network"), "1.12.1.34")
     address = "1.12.1.34"
     self.assertEqual(ipaddr.ipaddr(address, "network"), "1.12.1.34")
     address = "1.12.1.35/31"
     self.assertEqual(ipaddr.ipaddr(address, "network"), "1.12.1.34")
     address = "1.12.1.34/24"
     self.assertEqual(ipaddr.ipaddr(address, "network"), "1.12.1.0")
Esempio n. 10
0
 def test_network(self):
     address = '1.12.1.34/32'
     self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
     address = '1.12.1.34/255.255.255.255'
     self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
     address = '1.12.1.34'
     self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
     address = '1.12.1.35/31'
     self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
     address = '1.12.1.34/24'
     self.assertEqual(ipaddr(address, 'network'), '1.12.1.0')
Esempio n. 11
0
 def test_network_wildcard(self):
     address = "1.12.1.0/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.0 0.0.0.255"
     )
     address = "1.12.1.0/25"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.0 0.0.0.127"
     )
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr.ipaddr(address, 'last_usable'), 'Not a network address')
     address = "1.12.1.36/28"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.32 0.0.0.15"
     )
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.32 0.0.0.15"
     )
     address = "1.12.1.36/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.36 0.0.0.1"
     )
     address = "1.12.1.37/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.36 0.0.0.1"
     )
     address = "1.12.1.36/32"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.36 0.0.0.0"
     )
     address = "1.12.1.254/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "network_wildcard"), "1.12.1.0 0.0.0.255"
     )
Esempio n. 12
0
 def test_range_usable(self):
     address = "1.12.1.0/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "range_usable"), "1.12.1.1-1.12.1.254"
     )
     address = "1.12.1.0/25"
     self.assertEqual(
         ipaddr.ipaddr(address, "range_usable"), "1.12.1.1-1.12.1.126"
     )
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr.ipaddr(address, 'last_usable'), 'Not a network address')
     address = "1.12.1.36/28"
     self.assertEqual(
         ipaddr.ipaddr(address, "range_usable"), "1.12.1.33-1.12.1.46"
     )
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(
         ipaddr.ipaddr(address, "range_usable"), "1.12.1.33-1.12.1.46"
     )
     address = "1.12.1.36/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "range_usable"), "1.12.1.36-1.12.1.37"
     )
     address = "1.12.1.37/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "range_usable"), "1.12.1.36-1.12.1.37"
     )
     address = "1.12.1.36/32"
     self.assertEqual(ipaddr.ipaddr(address, "range_usable"), None)
     address = "1.12.1.254/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "range_usable"), "1.12.1.1-1.12.1.254"
     )
 def test_network_netmask(self):
     address = "1.12.1.0/24"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.0 255.255.255.0"
     )
     address = "1.12.1.0/25"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.0 255.255.255.128"
     )
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'last_usable'), 'Not a network address')
     address = "1.12.1.36/28"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.32 255.255.255.240"
     )
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.32 255.255.255.240"
     )
     address = "1.12.1.36/31"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.36 255.255.255.254"
     )
     address = "1.12.1.37/31"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.36 255.255.255.254"
     )
     address = "1.12.1.36/32"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.36 255.255.255.255"
     )
     address = "1.12.1.254/24"
     self.assertEqual(
         ipaddr(address, "network_netmask"), "1.12.1.0 255.255.255.0"
     )
Esempio n. 14
0
 def test_ip_netmask(self):
     address = "1.12.1.0/24"
     self.assertEqual(ipaddr.ipaddr(address, "ip_netmask"), None)
     address = "1.12.1.0/25"
     self.assertEqual(ipaddr.ipaddr(address, "ip_netmask"), None)
     address = "1.12.1.36/28"
     self.assertEqual(
         ipaddr.ipaddr(address, "ip_netmask"), "1.12.1.36 255.255.255.240"
     )
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(
         ipaddr.ipaddr(address, "ip_netmask"), "1.12.1.36 255.255.255.240"
     )
     address = "1.12.1.36/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "ip_netmask"), "1.12.1.36 255.255.255.254"
     )
     address = "1.12.1.37/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "ip_netmask"), "1.12.1.37 255.255.255.254"
     )
     address = "1.12.1.36/32"
     self.assertEqual(ipaddr.ipaddr(address, "ip_netmask"), None)
     address = "1.12.1.254/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "ip_netmask"), "1.12.1.254 255.255.255.0"
     )
Esempio n. 15
0
 def test_range_usable(self):
     address = '1.12.1.0/24'
     self.assertEqual(ipaddr(address, 'range_usable'),
                      '1.12.1.1-1.12.1.254')
     address = '1.12.1.0/25'
     self.assertEqual(ipaddr(address, 'range_usable'),
                      '1.12.1.1-1.12.1.126')
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'last_usable'), 'Not a network address')
     address = '1.12.1.36/28'
     self.assertEqual(ipaddr(address, 'range_usable'),
                      '1.12.1.33-1.12.1.46')
     address = '1.12.1.36/255.255.255.240'
     self.assertEqual(ipaddr(address, 'range_usable'),
                      '1.12.1.33-1.12.1.46')
     address = '1.12.1.36/31'
     self.assertEqual(ipaddr(address, 'range_usable'),
                      '1.12.1.36-1.12.1.37')
     address = '1.12.1.37/31'
     self.assertEqual(ipaddr(address, 'range_usable'),
                      '1.12.1.36-1.12.1.37')
     address = '1.12.1.36/32'
     self.assertEqual(ipaddr(address, 'range_usable'), None)
     address = '1.12.1.254/24'
     self.assertEqual(ipaddr(address, 'range_usable'),
                      '1.12.1.1-1.12.1.254')
Esempio n. 16
0
 def test_network_prefix(self):
     address = "1.12.1.0/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.0/24"
     )
     address = "1.12.1.0/25"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.0/25"
     )
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr.ipaddr(address, 'last_usable'), 'Not a network address')
     address = "1.12.1.36/28"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.32/28"
     )
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.32/28"
     )
     address = "1.12.1.36/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.36/31"
     )
     address = "1.12.1.37/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.36/31"
     )
     address = "1.12.1.36/32"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.36/32"
     )
     address = "1.12.1.254/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "network/prefix"), "1.12.1.0/24"
     )
Esempio n. 17
0
 def test_previous_usable(self):
     address = "1.12.1.0/24"
     self.assertEqual(ipaddr.ipaddr(address, "previous_usable"), None)
     address = "1.12.1.36/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "previous_usable"), "1.12.1.35"
     )
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr.ipaddr(address, 'last_usable'), 'Not a network address')
     address = "1.12.1.36/28"
     self.assertEqual(
         ipaddr.ipaddr(address, "previous_usable"), "1.12.1.35"
     )
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(
         ipaddr.ipaddr(address, "previous_usable"), "1.12.1.35"
     )
     address = "1.12.1.36/31"
     self.assertEqual(ipaddr.ipaddr(address, "previous_usable"), None)
     address = "1.12.1.37/31"
     self.assertEqual(
         ipaddr.ipaddr(address, "previous_usable"), "1.12.1.36"
     )
     address = "1.12.1.36/32"
     self.assertEqual(ipaddr.ipaddr(address, "previous_usable"), None)
     address = "1.12.1.254/24"
     self.assertEqual(
         ipaddr.ipaddr(address, "previous_usable"), "1.12.1.253"
     )
Esempio n. 18
0
 def test_network_wildcard(self):
     address = '1.12.1.0/24'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.0 0.0.0.255')
     address = '1.12.1.0/25'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.0 0.0.0.127')
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'last_usable'), 'Not a network address')
     address = '1.12.1.36/28'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.32 0.0.0.15')
     address = '1.12.1.36/255.255.255.240'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.32 0.0.0.15')
     address = '1.12.1.36/31'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.36 0.0.0.1')
     address = '1.12.1.37/31'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.36 0.0.0.1')
     address = '1.12.1.36/32'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.36 0.0.0.0')
     address = '1.12.1.254/24'
     self.assertEqual(ipaddr(address, 'network_wildcard'),
                      '1.12.1.0 0.0.0.255')
Esempio n. 19
0
 def test_network_netmask(self):
     address = '1.12.1.0/24'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.0 255.255.255.0')
     address = '1.12.1.0/25'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.0 255.255.255.128')
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'last_usable'), 'Not a network address')
     address = '1.12.1.36/28'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.32 255.255.255.240')
     address = '1.12.1.36/255.255.255.240'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.32 255.255.255.240')
     address = '1.12.1.36/31'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.36 255.255.255.254')
     address = '1.12.1.37/31'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.36 255.255.255.254')
     address = '1.12.1.36/32'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.36 255.255.255.255')
     address = '1.12.1.254/24'
     self.assertEqual(ipaddr(address, 'network_netmask'),
                      '1.12.1.0 255.255.255.0')
Esempio n. 20
0
 def test_ipaddr_address_query(self):
     self.assertEqual(ipaddr.ipaddr("192.0.2.230", "address"),
                      "192.0.2.230")
     self.assertEqual(ipaddr.ipaddr("192.0.2.230/24", "address"),
                      "192.0.2.230")
     self.assertIsNone(ipaddr.ipaddr("192.0.2.0/24", "address"))
     self.assertEqual(ipaddr.ipaddr("192.0.2.0/31", "address"), "192.0.2.0")
     self.assertEqual(ipaddr.ipaddr("2001::1", "address"), "2001::1")
     self.assertEqual(ipaddr.ipaddr("2001::1/48", "address"), "2001::1")
     self.assertEqual(ipaddr.ipaddr("2001::", "address"), "2001::")
     self.assertEqual(ipaddr.ipaddr("2001::/48", "address"), "2001::")
Esempio n. 21
0
 def test_ipaddr_public_query(self):
     self.assertIsNone(ipaddr.ipaddr("192.168.1.12", "public"))
     self.assertIsNone(ipaddr.ipaddr("127.0.1.25", "public"))
     self.assertIsNone(ipaddr.ipaddr("255.255.240.0", "public"))
     self.assertEqual(
         ipaddr.ipaddr("76.120.99.190", "public"), "76.120.99.190"
     )
     self.assertEqual(
         ipaddr.ipaddr(
             ["192.168.1.12", "127.0.1.25", "255.255.240.0"], "public"
         ),
         [],
     )
     self.assertEqual(
         ipaddr.ipaddr(
             [
                 "192.168.1.12",
                 "127.0.1.25",
                 "255.255.240.0",
                 "76.120.99.190",
             ],
             "public",
         ),
         ["76.120.99.190"],
     )
Esempio n. 22
0
    def test_last_usable(self):
        with pytest.raises(AnsibleFilterError, match="Not a network address"):
            ipaddr.ipaddr("1.12.1.34", "last_usable")

        address = "1.12.1.0/24"
        self.assertEqual(ipaddr.ipaddr(address, "last_usable"), "1.12.1.254")
        address = "1.12.1.36/24"
        self.assertEqual(ipaddr.ipaddr(address, "last_usable"), "1.12.1.254")
        address = "1.12.1.36/28"
        self.assertEqual(ipaddr.ipaddr(address, "last_usable"), "1.12.1.46")
        address = "1.12.1.36/255.255.255.240"
        self.assertEqual(ipaddr.ipaddr(address, "last_usable"), "1.12.1.46")
        address = "1.12.1.36/31"
        self.assertEqual(ipaddr.ipaddr(address, "last_usable"), "1.12.1.37")
        address = "1.12.1.37/31"
        self.assertEqual(ipaddr.ipaddr(address, "last_usable"), "1.12.1.37")
        address = "1.12.1.36/32"
        self.assertEqual(ipaddr.ipaddr(address, "last_usable"), None)
Esempio n. 23
0
 def test_ipaddr_empty_query(self):
     self.assertEqual(ipaddr.ipaddr("192.0.2.230"), "192.0.2.230")
     self.assertEqual(ipaddr.ipaddr("192.0.2.230/30"), "192.0.2.230/30")
     self.assertEqual(ipaddr.ipaddr([]), [])
     with pytest.raises(
             AnsibleFilterError,
             match="True is not a valid IP address or network",
     ):
         ipaddr.ipaddr(True)
     with pytest.raises(AnsibleFilterError,
                        match="'' is not a valid IP address or network"):
         ipaddr.ipaddr("")
Esempio n. 24
0
 def test_network_prefix(self):
     address = '1.12.1.0/24'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.0/24')
     address = '1.12.1.0/25'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.0/25')
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'last_usable'), 'Not a network address')
     address = '1.12.1.36/28'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.32/28')
     address = '1.12.1.36/255.255.255.240'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.32/28')
     address = '1.12.1.36/31'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.36/31')
     address = '1.12.1.37/31'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.36/31')
     address = '1.12.1.36/32'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.36/32')
     address = '1.12.1.254/24'
     self.assertEqual(ipaddr(address, 'network/prefix'), '1.12.1.0/24')
Esempio n. 25
0
 def test_previous_usable(self):
     address = '1.12.1.0/24'
     self.assertEqual(ipaddr(address, 'previous_usable'), None)
     address = '1.12.1.36/24'
     self.assertEqual(ipaddr(address, 'previous_usable'), '1.12.1.35')
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'last_usable'), 'Not a network address')
     address = '1.12.1.36/28'
     self.assertEqual(ipaddr(address, 'previous_usable'), '1.12.1.35')
     address = '1.12.1.36/255.255.255.240'
     self.assertEqual(ipaddr(address, 'previous_usable'), '1.12.1.35')
     address = '1.12.1.36/31'
     self.assertEqual(ipaddr(address, 'previous_usable'), None)
     address = '1.12.1.37/31'
     self.assertEqual(ipaddr(address, 'previous_usable'), '1.12.1.36')
     address = '1.12.1.36/32'
     self.assertEqual(ipaddr(address, 'previous_usable'), None)
     address = '1.12.1.254/24'
     self.assertEqual(ipaddr(address, 'previous_usable'), '1.12.1.253')
Esempio n. 26
0
    def test_ipaddr_6to4_query(self):
        v6_address = "2002:c000:02e6::1/48"
        self.assertEqual(ipaddr.ipaddr("192.0.2.230", "6to4"), v6_address)
        self.assertEqual(ipaddr.ipaddr("192.0.2.230/24", "6to4"), v6_address)
        self.assertFalse(ipaddr.ipaddr("192.0.2.0/24", "6to4"))

        self.assertFalse(ipaddr.ipaddr("fd::e", "6to4"))
        self.assertFalse(ipaddr.ipaddr("fd::e/20", "6to4"))

        self.assertEqual(ipaddr.ipaddr("2002:c000:02e6::1", "6to4"),
                         "2002:c000:02e6::1")
        self.assertEqual(ipaddr.ipaddr(v6_address, "6to4"), v6_address)
        self.assertEqual(
            ipaddr.ipaddr(
                ["192.0.2.230", "192.0.2.0/24", "fd::e", "2002:c000:02e6::1"],
                "6to4",
            ),
            [v6_address, "2002:c000:02e6::1"],
        )
Esempio n. 27
0
 def test_size_usable(self):
     address = '1.12.1.0/24'
     self.assertEqual(ipaddr(address, 'size_usable'), 254)
     address = '1.12.1.0/25'
     self.assertEqual(ipaddr(address, 'size_usable'), 126)
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'last_usable'), 'Not a network address')
     address = '1.12.1.36/28'
     self.assertEqual(ipaddr(address, 'size_usable'), 14)
     address = '1.12.1.36/255.255.255.240'
     self.assertEqual(ipaddr(address, 'size_usable'), 14)
     address = '1.12.1.36/31'
     self.assertEqual(ipaddr(address, 'size_usable'), 2)
     address = '1.12.1.37/31'
     self.assertEqual(ipaddr(address, 'size_usable'), 2)
     address = '1.12.1.36/32'
     self.assertEqual(ipaddr(address, 'size_usable'), 0)
     address = '1.12.1.254/24'
     self.assertEqual(ipaddr(address, 'size_usable'), 254)
Esempio n. 28
0
 def test_size_usable(self):
     address = "1.12.1.0/24"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 254)
     address = "1.12.1.0/25"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 126)
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr.ipaddr(address, 'last_usable'), 'Not a network address')
     address = "1.12.1.36/28"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 14)
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 14)
     address = "1.12.1.36/31"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 2)
     address = "1.12.1.37/31"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 2)
     address = "1.12.1.36/32"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 0)
     address = "1.12.1.254/24"
     self.assertEqual(ipaddr.ipaddr(address, "size_usable"), 254)
 def test_first_usable(self):
     address = "1.12.1.0/24"
     self.assertEqual(ipaddr(address, "first_usable"), "1.12.1.1")
     address = "1.12.1.36/24"
     self.assertEqual(ipaddr(address, "first_usable"), "1.12.1.1")
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'first_usable'), 'Not a network address')
     address = "1.12.1.36/28"
     self.assertEqual(ipaddr(address, "first_usable"), "1.12.1.33")
     address = "1.12.1.36/255.255.255.240"
     self.assertEqual(ipaddr(address, "first_usable"), "1.12.1.33")
     address = "1.12.1.36/31"
     self.assertEqual(ipaddr(address, "first_usable"), "1.12.1.36")
     address = "1.12.1.37/31"
     self.assertEqual(ipaddr(address, "first_usable"), "1.12.1.36")
     address = "1.12.1.36/32"
     self.assertEqual(ipaddr(address, "first_usable"), None)
Esempio n. 30
0
 def test_first_usable(self):
     address = '1.12.1.0/24'
     self.assertEqual(ipaddr(address, 'first_usable'), '1.12.1.1')
     address = '1.12.1.36/24'
     self.assertEqual(ipaddr(address, 'first_usable'), '1.12.1.1')
     # address = '1.12.1.34'
     # self.assertFalse(ipaddr(address, 'first_usable'), 'Not a network address')
     address = '1.12.1.36/28'
     self.assertEqual(ipaddr(address, 'first_usable'), '1.12.1.33')
     address = '1.12.1.36/255.255.255.240'
     self.assertEqual(ipaddr(address, 'first_usable'), '1.12.1.33')
     address = '1.12.1.36/31'
     self.assertEqual(ipaddr(address, 'first_usable'), '1.12.1.36')
     address = '1.12.1.37/31'
     self.assertEqual(ipaddr(address, 'first_usable'), '1.12.1.36')
     address = '1.12.1.36/32'
     self.assertEqual(ipaddr(address, 'first_usable'), None)