def fetch():
    a = IPSet([])
    for blocklist in blocklists:
        syslog.syslog('generate-blacklist.py - fetching prefixes from: %s ' %
                      blocklist)
        #print blocklist
        r = requests.get(blocklist)
        for line in r.iter_lines():
            # Dont ask me why but like this it works.
            if line != "0.0.0.0/8" and line != "240.0.0.0/4" and line != "224.0.0.0/4":
                if linefilter(line):
                    myprefix = makeprefix(linefilter(line))
                    #a.add(makeprefix(linefilter(line)))
                    a.add(myprefix)
    for prefix in b:
        if b.len() > 0 and b.__contains__(
                prefix) and not a.__contains__(prefix):
            a.discard(prefix)
            stdout.write('withdraw route ' + str(prefix) + nexthop)
            stdout.flush()
    for prefix in a:
        if a.__contains__(prefix) and not b.__contains__(prefix):
            stdout.write('announce route ' + str(prefix) + nexthop)
            stdout.flush()
    b.add(a)
Esempio n. 2
0
def fetch():
    a = IPSet([])
    totalnoofnewprefixes = 0
    for blocklist in blocklists:
        syslog.syslog('{0} fetching prefixes from: {1}'.format(syslogprefix, blocklist))
#	'{0} in {1}'.format(unicode(self.author,'utf-8'),  unicode(self.publication,'utf-8'))
        r = requests.get(blocklist)
        for line in r.iter_lines():
            # Dont ask me why but like this it works. 
            if line != "0.0.0.0/8" and line != "240.0.0.0/4" and line != "224.0.0.0/4":
                if linefilter(line):
                    myprefix = makeprefix(linefilter(line))
#                   if myprefix not in a                    
		    a.add(myprefix)
        noofprefixes = a.__len__
        syslog.syslog('{0} got {1} prefixes from: {2}'.format(syslogprefix, noofprefixes, blocklist))
        totalnoofnewprefixes = totalnoofnewprefixes + noofprefixes
    syslog.syslog('{0} got {1} prefixes in total from upstream'.format(syslogprefix, totalnoofprefixes))
    for prefix in b:
        if b.len() > 0 and b.__contains__(prefix) and not a.__contains__(prefix):
            a.discard(prefix)
            stdout.write('withdraw route ' + str(prefix) + nexthop)
            stdout.flush()

    for prefix in a:
        if a.__contains__(prefix) and not b.__contains__(prefix):
            stdout.write('announce route ' + str(prefix) + nexthop)
            stdout.flush()

    b.add(a)
def fetch():
	a = IPSet([])
	for blocklist in blocklists:
		r = requests.get(blocklist)
		for line in r.iter_lines():
			if linefilter(line):
				a.add(makeprefix(linefilter(line)))

	for prefix in b:
		if b.len() > 0 and b.__contains__(prefix) and not a.__contains__(prefix):
			a.discard(prefix)
			stdout.write('withdraw route ' + str(prefix) + nexthop)
			stdout.flush()

	for prefix in a:
		if a.__contains__(prefix) and not b.__contains__(prefix):
			stdout.write('announce route ' + str(prefix) + nexthop)
			stdout.flush()

	b.add(a)
def fetch():
    a = IPSet([])
    for blocklist in blocklists:
        r = requests.get(blocklist)
        for line in r.iter_lines():
            if linefilter(line):
                a.add(makeprefix(linefilter(line)))

    for prefix in b:
        if b.len() > 0 and b.__contains__(
                prefix) and not a.__contains__(prefix):
            a.discard(prefix)
            stdout.write('withdraw route ' + str(prefix) + nexthop)
            stdout.flush()

    for prefix in a:
        if a.__contains__(prefix) and not b.__contains__(prefix):
            stdout.write('announce route ' + str(prefix) + nexthop)
            stdout.flush()

    b.add(a)