将域名批量转换为ip地址。本文章没有做去重,有时间的自己去做个去重的小功能!
import threading
import time
from concurrent.futures import ThreadPoolExecutor
from socket import gethostbyname
glock = threading.Lock()
executor = ThreadPoolExecutor(max_workers=2000)
blacklist = []//自己定义不转化的类型
def check_domain_list(dm):
for h in blacklist:
if h in dm:
return "无效"
else:
return dm
def to_ip(line):
good_domain = check_domain_list(line)
if good_domain == "无效":
print(line)
else:
try:
host = gethostbyname(good_domain.strip('\n'))
except Exception as e:
print(e)
else:
write_data("xxx.txt", host + '\n')
print("进行到:"+line)
def write_data(path, data):
glock.acquire()
with open(path, 'a', encoding='utf-8') as f:
f.write(data)
glock.release()
if __name__ == '__main__':
with open("xx.txt", 'r') as f:
for line in f.readlines():
executor.submit(to_ip, (line))