Ejemplo n.º 1
0
def gen_ip(network_with_mask):
    ip_list = []
    ip_network = IPNetwork(network_with_mask)
    #print "ab"
    #print ip_network
    for ip in ip_network.iterhosts():
        ip_list.append(ip.compressed)
    #print "ccc"
    #print ip

    for ip in ip_list:
        #print ip
        #print ip_list
        #print "dd"
        if int(ip.split('.')[3]) < 13 or int(ip.split('.')[3]) > 253:
            continue
        exist_status = Container.objects.filter(container_ip=ip)
        #print "asss"
        #print exist_status
        #print "ipsss"
        #print ip
        if exist_status.count() == 0:
            #print exist_status.count()
            exist_status = Host.objects.filter(ip=ip)
            #print exist_status
            if exist_status.count() == 0:
                #print ip
                return ip
            else:
                continue
        else:
            continue
    return "error: no ip will use"
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        if len(args) == 0:
            network, pattern = self.defaultnetwork, self.defaultpattern
        if len(args) == 1:
            network, pattern = IPNetwork(args[0]), self.defaultpattern
        if len(args) == 2:
            network, pattern = IPNetwork(args[0]), args[1]

        for ip in network.iterhosts():
            name = reverse(ip)
            content = pattern % dict(
                [(str(k), v) for k, v in enumerate(str(ip).split('.'))])

            # print "%s\tcreated: %s" % (
            #     Record.objects.get_or_create(domain=self.get_domain(content),
            #         name=content, type='A', defaults={'content': str(ip)}))
            print "%s\t\tcreated: %s" % (
                Record.objects.get_or_create(domain=self.get_domain(name),
                    name=name, type='PTR', defaults={'content': content}))
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        if len(args) == 0:
            network, pattern = self.defaultnetwork, self.defaultpattern
        if len(args) == 1:
            network, pattern = IPNetwork(args[0]), self.defaultpattern
        if len(args) == 2:
            network, pattern = IPNetwork(args[0]), args[1]

        for ip in network.iterhosts():
            name = reverse(ip)
            content = pattern % dict(
                [(str(k), v) for k, v in enumerate(str(ip).split('.'))])

            # print "%s\tcreated: %s" % (
            #     Record.objects.get_or_create(domain=self.get_domain(content),
            #         name=content, type='A', defaults={'content': str(ip)}))
            print "%s\t\tcreated: %s" % (Record.objects.get_or_create(
                domain=self.get_domain(name),
                name=name,
                type='PTR',
                defaults={'content': content}))
Ejemplo n.º 4
0
# validate command-line options
try:
    peer_ip = IPAddress(args.peer_ip)
except:
    print 'invalid peer address "%s" - aborting' % args.peer_ip
    sys.exit(1)
try:
    local_cidr = IPNetwork(args.local_cidr)
except:
    print 'invalid local addresses block "%s" - aborting' % args.local_cidr
    sys.exit(1)
if args.announce_cidr:
    try:
        announce_cidr = IPNetwork(args.announce_cidr)
        announce_cidr = announce_cidr.iterhosts()
    except:
        print 'invalid announce addresses block %s - aborting' % args.announce_cidr
        sys.exit(1)

# create ExaBGP configuration + setup address aliases if required
configuration = 'group peers {\n'
sessions      = 0
for address in local_cidr.iterhosts():
    configuration += ('  neighbor %s {\n'
                      '    router-id %s;\n'
                      '    local-address %s;\n'
                      '    local-as %s;\n'
                      '    peer-as %s;\n'
                      '    family {\n'
                      '      inet4 unicast;\n'
Ejemplo n.º 5
0
# validate command-line options
try:
    peer_ip = IPAddress(args.peer_ip)
except:
    print 'invalid peer address "%s" - aborting' % args.peer_ip
    sys.exit(1)
try:
    local_cidr = IPNetwork(args.local_cidr)
except:
    print 'invalid local addresses block "%s" - aborting' % args.local_cidr
    sys.exit(1)
if args.announce_cidr:
    try:
        announce_cidr = IPNetwork(args.announce_cidr)
        announce_cidr = announce_cidr.iterhosts()
    except:
        print 'invalid announce addresses block %s - aborting' % args.announce_cidr
        sys.exit(1)

# create ExaBGP configuration + setup address aliases if required
configuration = 'group peers {\n'
sessions = 0
for address in local_cidr.iterhosts():
    configuration += ('  neighbor %s {\n'
                      '    router-id %s;\n'
                      '    local-address %s;\n'
                      '    local-as %s;\n'
                      '    peer-as %s;\n'
                      '    family {\n'
                      '      inet4 unicast;\n'