From 7f6db649bfd26c2f59c3cc26440af77591269109 Mon Sep 17 00:00:00 2001 From: Sheng Date: Thu, 19 Sep 2019 10:55:34 +0800 Subject: [PATCH] Support link scope ipv6 address --- tests/test_utils.py | 4 ++++ webssh/utils.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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):