#-*- coding:utf-8 -*- import fileinput import re import os import shutil defreadIp(): with open(r'/root/python/honeypot.log', 'r') as f: for line in f.readlines(): result2 = re.findall('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',line) #匹配ip正则表达式 ifnot result2 == []: result = result2[0] + '\n' with open('/root/python/ip.txt', 'a+') as w: w.write(result) defsetIp():#去重 a=0 readDir = "/root/python/ip.txt" writeDir = "/root/python/newip.txt"#new lines_seen = set() outfile = open(writeDir, "w") f = open(readDir, "r") for line in f: if line notin lines_seen: a+=1 outfile.write(line) lines_seen.add(line) print(a) outfile.close() defreadDns(): with open(r'/root/python/newip.txt', 'r') as g: for i in g.readlines(): com=os.popen('nslookup %s'%i) comm=com.read() if comm.find('NXDOMAIN')==-1: print comm if __name__ == '__main__': readIp() setIp() readDns()