import os, sys from socket import gethostbyname # DOMAIN= "G:/PycharmProject/fullstack2/week1/domain.txt" def main(): # domain.txt里面存储的是需要批量解析的域名列表,一行一个 with open("domains.txt", 'r') as f: for line in f.readlines(): try: host = gethostbyname(line.strip(' ')) except Exception as e: print(e) else: # result.txt里面存储的是批量解析后的结果,不用提前创建 with open('result.txt', 'a+') as r: r.write(line.strip(' ') + ' ') r.write(host + ' ') if __name__ == '__main__': main()
转载博客:钟桂耀