MCPcopy Create free account
hub / github.com/apenwarr/sshuttle / parse_ipport

Function parse_ipport

main.py:30–44  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

28
29# 1.2.3.4:567 or just 1.2.3.4 or just 567
30def parse_ipport(s):
31 s = str(s)
32 m = re.match(r'(?:(\d+)\.(\d+)\.(\d+)\.(\d+))?(?::)?(?:(\d+))?$', s)
33 if not m:
34 raise Fatal('%r is not a valid IP:port format' % s)
35 (a,b,c,d,port) = m.groups()
36 (a,b,c,d,port) = (int(a or 0), int(b or 0), int(c or 0), int(d or 0),
37 int(port or 0))
38 if a > 255 or b > 255 or c > 255 or d > 255:
39 raise Fatal('%d.%d.%d.%d has numbers > 255' % (a,b,c,d))
40 if port > 65535:
41 raise Fatal('*:%d is greater than the maximum of 65535' % port)
42 if a == None:
43 a = b = c = d = 0
44 return ('%d.%d.%d.%d' % (a,b,c,d), port)
45
46
47optspec = """

Callers 1

main.pyFile · 0.85

Calls 1

FatalClass · 0.85

Tested by

no test coverage detected