Skip to content

Commit

Permalink
Correct IPv6 parsing in command-line. Fixes #26.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthepsy committed May 5, 2017
1 parent 96d442e commit d8eb46d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ssh-audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,17 @@ def from_cmdline(cls, args, usage_cb):
usage_cb()
if oport is not None:
host = args[0]
port = utils.parse_int(oport)
else:
s = args[0].split(':')
host = s[0].strip()
if len(s) == 2:
oport, port = s[1], utils.parse_int(s[1])
mx = re.match(r'^\[([^\]]+)\](?::(.*))?$', args[0])
if bool(mx):
host, oport = mx.group(1), mx.group(2)
else:
oport, port = '22', 22
s = args[0].split(':')
if len(s) > 2:
host, oport = args[0], '22'
else:
host, oport = s[0], s[1] if len(s) > 1 else '22'
port = utils.parse_int(oport)
if not host:
usage_cb('host is empty')
if port <= 0 or port > 65535:
Expand Down
8 changes: 8 additions & 0 deletions test/test_auditconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ def test_audit_conf_cmdline(self):
self._test_conf(conf, host='localhost', port=2222)
conf = c('-p 2222 localhost')
self._test_conf(conf, host='localhost', port=2222)
conf = c('2001:4860:4860::8888')
self._test_conf(conf, host='2001:4860:4860::8888')
conf = c('[2001:4860:4860::8888]:22')
self._test_conf(conf, host='2001:4860:4860::8888')
conf = c('[2001:4860:4860::8888]:2222')
self._test_conf(conf, host='2001:4860:4860::8888', port=2222)
conf = c('-p 2222 2001:4860:4860::8888')
self._test_conf(conf, host='2001:4860:4860::8888', port=2222)
with pytest.raises(SystemExit):
conf = c('localhost:')
with pytest.raises(SystemExit):
Expand Down

0 comments on commit d8eb46d

Please sign in to comment.