def test_get_ip_in_src_and_not_in_dst(self):
        source = CidrRange("1.1.1.0/24")
        target = CidrRange("2.2.2.0/24")

        # IP not in both
        assert get_ip_in_src_and_not_in_dst(["3.3.3.3", "4.4.4.4"], source, target) is None

        # IP not in source, in target
        assert (get_ip_in_src_and_not_in_dst(["2.2.2.2"], source, target)) is None

        # IP in source, not in target
        assert get_ip_in_src_and_not_in_dst(["8.8.8.8", "1.1.1.1"], source, target)

        # IP in both subnets
        assert (get_ip_in_src_and_not_in_dst(["8.8.8.8", "1.1.1.1"], source, source)) is None
Beispiel #2
0
def get_interfaces_ranges():
    """
    Returns a list of IPs accessible in the host in each network interface, in the subnet.
    Limits to a single class C if the network is larger
    :return: List of IPs, marked as strings.
    """
    res = []
    ifs = get_host_subnets()
    for net_interface in ifs:
        address_str = net_interface["addr"]
        netmask_str = net_interface["netmask"]
        # limit subnet scans to class C only
        res.append(CidrRange(cidr_range="%s/%s" % (address_str, netmask_str)))
    return res
    def test_get_ip_in_src_and_not_in_dst(self):
        self.fail_if_not_testing_env()
        source = CidrRange("1.1.1.0/24")
        target = CidrRange("2.2.2.0/24")

        # IP not in both
        self.assertIsNone(get_ip_in_src_and_not_in_dst(
            ["3.3.3.3", "4.4.4.4"], source, target
        ))

        # IP not in source, in target
        self.assertIsNone(get_ip_in_src_and_not_in_dst(
            ["2.2.2.2"], source, target
        ))

        # IP in source, not in target
        self.assertIsNotNone(get_ip_in_src_and_not_in_dst(
            ["8.8.8.8", "1.1.1.1"], source, target
        ))

        # IP in both subnets
        self.assertIsNone(get_ip_in_src_and_not_in_dst(
            ["8.8.8.8", "1.1.1.1"], source, source
        ))
Beispiel #4
0
 def setUp(self):
     self.cidr_range = CidrRange("10.0.0.0/28",
                                 False)  # this gives us 15 hosts
     self.local_host_range = SingleIpRange('localhost')
     self.random_single_ip_range = SingleIpRange('41.50.13.37')