csum = 0 asNum = "" ass = "" for c in content: c = c.split('\t') if cmp(c[0], lastAS) != 0: asNum = c[0] ass = c[2] csum = 0 sum = 0 if lastCN > 0: fcn.write(printLine) ips = c[1].split('/') ip = ips[0] for i in range(0, int(2**(24-int(ips[1])))): if cn.has_key(ip): f.write('%s\t%s\t%d\t%s\n' % (asNum, ip, 1, ass)) fcnip.write('%s\t%s\n' % (ip, asNum)) csum = csum + 1 else: f.write('%s\t%s\t%d\t%s\n' % (asNum, ip, 0, ass)) ip = ipUtil.ipadd256(ip) sum = sum + 1 if csum > 0: printLine = '%s\t%d\t%d\t%f\n' % (asNum, sum, csum, csum/sum*100) lastAS = asNum lastCN = csum f.close() fcn.close() fcnip.close()
import sys, ipUtil f = open(sys.argv[1]) content = f.read() f.close() content = content.split('\n') as2ips = {} for c in content: if c.strip() == "": continue c = c.split('\t') as2ips[c[0]] = c[1] f = open(sys.argv[2]) content = f.read() f.close() content = content.split('\n') f = file(sys.argv[3], 'w') for c in content: if c.strip() == "": continue c = c.split('\t') if as2ips.has_key(c[1]): f.write('%s\t%s\t%s\n' % (ipUtil.dottedQuadToNum(c[0]), ipUtil.dottedQuadToNum(ipUtil.ipadd256(c[0]))-1, as2ips[c[1]])) else: f.write('%s\t%s\tETC\n' % (ipUtil.dottedQuadToNum(c[0]), ipUtil.dottedQuadToNum(ipUtil.ipadd256(c[0]))-1)) f.close()