Skip to content

Commit

Permalink
Merge pull request #735 from mangano-ito/allows-wildcard-hosts
Browse files Browse the repository at this point in the history
Allows wildcard host names as subnets
  • Loading branch information
brianmay committed Feb 10, 2022
2 parents d8a07a5 + 016919c commit bfd6f5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sshuttle/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def parse_subnetport_file(s):
def parse_subnetport(s):

if s.count(':') > 1:
rx = r'(?:\[?([\w\:]+)(?:/(\d+))?]?)(?::(\d+)(?:-(\d+))?)?$'
rx = r'(?:\[?(?:\*\.)?([\w\:]+)(?:/(\d+))?]?)(?::(\d+)(?:-(\d+))?)?$'
else:
rx = r'([\w\.\-]+)(?:/(\d+))?(?::(\d+)(?:-(\d+))?)?$'
rx = r'((?:\*\.)?[\w\.\-]+)(?:/(\d+))?(?::(\d+)(?:-(\d+))?)?$'

m = re.match(rx, s)
if not m:
Expand Down
19 changes: 19 additions & 0 deletions tests/client/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def _mock_getaddrinfo(host, *_):
(socket.AF_INET6, socket.SOCK_STREAM, 0, '', ('::1', 0, 0, 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, [])


Expand Down Expand Up @@ -133,6 +137,11 @@ def test_parse_subnetport_host(mock_getaddrinfo):
(socket.AF_INET6, '::1', 128, 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)
Expand All @@ -157,3 +166,13 @@ def test_parse_subnetport_host_with_port(mock_getaddrinfo):
(socket.AF_INET6, '::1', 128, 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),
])

0 comments on commit bfd6f5d

Please sign in to comment.