Beispiel #1
0
def _create_ip_address(host, port):
    if not isinstance(host, six.text_type):
        raise ValueError(
            "'host' must be {}, not {}".format(six.text_type, type(host))
        )
    try:
        a = ipaddress.ip_address(host)
    except ValueError:
        a = None
    if isinstance(a, ipaddress.IPv4Address):
        return IPv4Address('TCP', host, port)
    if isinstance(a, ipaddress.IPv6Address):
        return IPv6Address('TCP', host, port)
    addr = HostnameAddress(host, port)
    addr.host = host
    return addr
Beispiel #2
0
def _create_ip_address(host, port):
    if not isinstance(host, six.text_type):
        raise ValueError(
            "'host' must be {}, not {}".format(six.text_type, type(host))
        )
    try:
        a = ipaddress.ip_address(host)
    except ValueError:
        a = None
    if isinstance(a, ipaddress.IPv4Address):
        return IPv4Address('TCP', host, port)
    if isinstance(a, ipaddress.IPv6Address):
        return IPv6Address('TCP', host, port)
    addr = HostnameAddress(host, port)
    addr.host = host
    return addr
Beispiel #3
0
 def test_match_ip_address_ipv6_hostname(self):
     matcher = NetfilterMatchIPAddress('2001:0db8:0:f101::1/128')
     context = NetfilterContext(addr=HostnameAddress('hathor.network', 80))
     self.assertFalse(matcher.match(context))
Beispiel #4
0
 def test_match_ip_address_ipv4_hostname(self):
     matcher = NetfilterMatchIPAddress('192.168.0.1/32')
     context = NetfilterContext(addr=HostnameAddress('hathor.network', 80))
     self.assertFalse(matcher.match(context))