示例#1
0
文件: socks.py 项目: meejah/txtorcon
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
示例#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
示例#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))
示例#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))