コード例 #1
0
ファイル: test_Utility.py プロジェクト: hawk90/ID2T
 def test_get_ip_range_backwards(self):
     end = "192.168.178.254"
     start = "192.168.179.1"
     result = [
         "192.168.179.1", "192.168.179.0", "192.168.178.255",
         "192.168.178.254"
     ]
     self.assertEqual(Utility.get_ip_range(start, end), result)
コード例 #2
0
        def append_ips(
                ip_address_input: t.List[str]) -> t.Tuple[bool, t.List[str]]:
            """
            Recursive appending function to handle lists and ranges of IP addresses.

            :param ip_address_input: The IP address(es) as list of strings, comma-separated or dash-separated string.
            :return: List of all given IP addresses.
            """
            ip_list = []
            is_valid = True
            for ip in ip_address_input:
                if '-' in ip:
                    ip_range = ip.split('-')
                    ip_range = Util.get_ip_range(ip_range[0], ip_range[1])
                    is_valid, ips = append_ips(ip_range)
                    ip_list.extend(ips)
                else:
                    try:
                        ipaddress.ip_address(ip)
                        ip_list.append(ip)
                    except ValueError:
                        return False, ip_list
            return is_valid, ip_list
コード例 #3
0
ファイル: test_Utility.py プロジェクト: hawk90/ID2T
 def test_get_ip_range_equal(self):
     end = "192.168.178.254"
     start = "192.168.178.254"
     result = ["192.168.178.254"]
     self.assertEqual(Utility.get_ip_range(start, end), result)