diff --git a/tests/test_utils.py b/tests/test_utils.py index 9916574..5ace48e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -35,6 +35,10 @@ class TestUitls(unittest.TestCase): self.assertFalse(is_valid_ip_address(b'abc')) self.assertTrue(is_valid_ip_address('::1')) self.assertTrue(is_valid_ip_address(b'::1')) + self.assertTrue(is_valid_ip_address('fe80::1111:2222:3333:4444')) + self.assertTrue(is_valid_ip_address(b'fe80::1111:2222:3333:4444')) + self.assertTrue(is_valid_ip_address('fe80::1111:2222:3333:4444%eth0')) + self.assertTrue(is_valid_ip_address(b'fe80::1111:2222:3333:4444%eth0')) def test_is_valid_port(self): self.assertTrue(is_valid_port(80)) diff --git a/webssh/utils.py b/webssh/utils.py index 9e73f12..5bb21e3 100644 --- a/webssh/utils.py +++ b/webssh/utils.py @@ -36,7 +36,10 @@ def to_int(string): def to_ip_address(ipstr): - return ipaddress.ip_address(to_str(ipstr)) + ip = to_str(ipstr) + if ip.startswith('fe80::'): + ip = ip.split('%')[0] + return ipaddress.ip_address(ip) def is_valid_ip_address(ipstr):