mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-14 09:58:14 +01:00
Merge pull request #735 from mangano-ito/allows-wildcard-hosts
Allows wildcard host names as subnets
This commit is contained in:
commit
bfd6f5d088
@ -37,9 +37,9 @@ def parse_subnetport_file(s):
|
|||||||
def parse_subnetport(s):
|
def parse_subnetport(s):
|
||||||
|
|
||||||
if s.count(':') > 1:
|
if s.count(':') > 1:
|
||||||
rx = r'(?:\[?([\w\:]+)(?:/(\d+))?]?)(?::(\d+)(?:-(\d+))?)?$'
|
rx = r'(?:\[?(?:\*\.)?([\w\:]+)(?:/(\d+))?]?)(?::(\d+)(?:-(\d+))?)?$'
|
||||||
else:
|
else:
|
||||||
rx = r'([\w\.\-]+)(?:/(\d+))?(?::(\d+)(?:-(\d+))?)?$'
|
rx = r'((?:\*\.)?[\w\.\-]+)(?:/(\d+))?(?::(\d+)(?:-(\d+))?)?$'
|
||||||
|
|
||||||
m = re.match(rx, s)
|
m = re.match(rx, s)
|
||||||
if not m:
|
if not m:
|
||||||
|
@ -38,6 +38,10 @@ def _mock_getaddrinfo(host, *_):
|
|||||||
(socket.AF_INET6, socket.SOCK_STREAM, 0, '', ('::1', 0, 0, 0)),
|
(socket.AF_INET6, socket.SOCK_STREAM, 0, '', ('::1', 0, 0, 0)),
|
||||||
(socket.AF_INET, socket.SOCK_STREAM, 0, '', ('127.0.0.1', 0)),
|
(socket.AF_INET, socket.SOCK_STREAM, 0, '', ('127.0.0.1', 0)),
|
||||||
],
|
],
|
||||||
|
"*.blogspot.com": [
|
||||||
|
(socket.AF_INET6, socket.SOCK_STREAM, 0, '', ('2404:6800:4004:821::2001', 0, 0, 0)),
|
||||||
|
(socket.AF_INET, socket.SOCK_STREAM, 0, '', ('142.251.42.129', 0)),
|
||||||
|
],
|
||||||
}.get(host, [])
|
}.get(host, [])
|
||||||
|
|
||||||
|
|
||||||
@ -133,6 +137,11 @@ def test_parse_subnetport_host(mock_getaddrinfo):
|
|||||||
(socket.AF_INET6, '::1', 128, 0, 0),
|
(socket.AF_INET6, '::1', 128, 0, 0),
|
||||||
(socket.AF_INET, '127.0.0.1', 32, 0, 0),
|
(socket.AF_INET, '127.0.0.1', 32, 0, 0),
|
||||||
])
|
])
|
||||||
|
assert set(sshuttle.options.parse_subnetport('*.blogspot.com')) \
|
||||||
|
== set([
|
||||||
|
(socket.AF_INET6, '2404:6800:4004:821::2001', 128, 0, 0),
|
||||||
|
(socket.AF_INET, '142.251.42.129', 32, 0, 0),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
@patch('sshuttle.options.socket.getaddrinfo', side_effect=_mock_getaddrinfo)
|
@patch('sshuttle.options.socket.getaddrinfo', side_effect=_mock_getaddrinfo)
|
||||||
@ -157,3 +166,13 @@ def test_parse_subnetport_host_with_port(mock_getaddrinfo):
|
|||||||
(socket.AF_INET6, '::1', 128, 445, 450),
|
(socket.AF_INET6, '::1', 128, 445, 450),
|
||||||
(socket.AF_INET, '127.0.0.1', 32, 445, 450),
|
(socket.AF_INET, '127.0.0.1', 32, 445, 450),
|
||||||
])
|
])
|
||||||
|
assert set(sshuttle.options.parse_subnetport('*.blogspot.com:80')) \
|
||||||
|
== set([
|
||||||
|
(socket.AF_INET6, '2404:6800:4004:821::2001', 128, 80, 80),
|
||||||
|
(socket.AF_INET, '142.251.42.129', 32, 80, 80),
|
||||||
|
])
|
||||||
|
assert set(sshuttle.options.parse_subnetport('*.blogspot.com:80-90')) \
|
||||||
|
== set([
|
||||||
|
(socket.AF_INET6, '2404:6800:4004:821::2001', 128, 80, 90),
|
||||||
|
(socket.AF_INET, '142.251.42.129', 32, 80, 90),
|
||||||
|
])
|
||||||
|
Loading…
Reference in New Issue
Block a user