def test_cidr8(self): cidrBIG = iplib.CIDR('192.0.0.0/8') cidrSMALL = iplib.CIDR('192.0.0.0/30') cidrFUNNY = iplib.CIDR('192.0.0.0/31') self.assertFalse(cidrBIG in cidrSMALL) self.assertTrue(cidrSMALL in cidrBIG) self.assertTrue(cidrBIG in cidrBIG) self.assertTrue(cidrSMALL in cidrSMALL) self.assertFalse(cidrSMALL in cidrFUNNY) self.assertTrue(cidrFUNNY in cidrSMALL)
def is_internal(request): if not request.META.has_key('REMOTE_ADDR'): return False else: main = iplib.CIDR('140.163.0.0/16') zrc = iplib.CIDR('172.16.0.0/12') vpn = iplib.CIDR('192.168.0.0/16') addr = request.META['REMOTE_ADDR'] if main.is_valid_ip(addr) or zrc.is_valid_ip(addr) or vpn.is_valid_ip( addr): return True else: return False
def test_cidr6(self): cidr = iplib.CIDR('127.0.0.1/31') ip1 = iplib.IPv4Address('127.0.0.0') ip2 = iplib.IPv4Address('127.0.0.1') self.assertTrue(ip1 in cidr) self.assertTrue(ip2 in cidr) self.assertFalse(iplib.IPv4Address('126.255.255.255') in cidr) self.assertFalse(iplib.IPv4Address('127.0.0.2') in cidr)
def test_cidr5(self): cidr = iplib.CIDR('127.0.0.1/10') ip1 = iplib.IPv4Address('127.0.0.1') ip2 = iplib.IPv4Address('127.0.0.2') ip3 = iplib.IPv4Address('127.20.10.5') ip4 = iplib.IPv4Address('127.63.255.254') ipN = iplib.IPv4Address('127.0.0.0') ipB = iplib.IPv4Address('127.63.255.255') self.assertTrue(ip1 in cidr) self.assertTrue(ip2 in cidr) self.assertTrue(ip3 in cidr) self.assertTrue(ip4 in cidr) self.assertFalse(ipN in cidr) self.assertFalse(ipB in cidr)
def get_free_ipaddress(request, id): clients_group = app_admin_models.ClientsGroups.objects.get(id=id) clients_used_ip = [client.ip_address for client in app_admin_models.Clients.objects.filter(select_clients_group=clients_group, deleted_user=False)] json_ip_addresses = {} free_ip_list = [] for network in clients_group.ipv4networks_list.all(): for ip_address in iplib.CIDR(str(network.ipv4networks) + "/" + str(network.CIDR)): if ip_address not in clients_used_ip and ip_address != network.ipv4networks: json_ip_addresses.update({str(ip_address):str(ip_address)}) break return HttpResponse( json.dumps(json_ip_addresses), content_type='application/json' )
def test_cidr_len(self): cidr = iplib.CIDR('127.0.0.1/28') self.assertFalse(len(cidr.get_all_valid_ip()) != 14)
def test_cidr7(self): cidr = iplib.CIDR('127.0.0.1/32') ip1 = iplib.IPv4Address('127.0.0.1') self.assertTrue(ip1 in cidr) self.assertFalse(iplib.IPv4Address('127.0.0.0') in cidr) self.assertFalse(iplib.IPv4Address('127.0.0.2') in cidr)
def test_cidr4(self): cidr1 = iplib.CIDR('127.0.0.1/26') cidr2 = iplib.CIDR('127.0.0.2/26') self.assertFalse(cidr1 >= cidr2)
def test_cidr2(self): cidr1 = iplib.CIDR('127.0.0.1/28') cidr2 = iplib.CIDR('0x7f000001', '037777777760') self.assertFalse(cidr1 != cidr2)
def test_cidr1(self): cidr1 = iplib.CIDR('127.0.0.1/28') cidr2 = iplib.CIDR('127.0.0.1', '28') self.assertFalse(cidr1 != cidr2)