# encoding: UTF-8 import socket rfile = open('c:\\ip.txt') wfile = open('c:\\result.csv', 'w+') for line in rfile: str = line.strip().split(';') for s in str: s = s.strip().split('/') s = s[0] try: result = socket.gethostbyname(s) except: result = "error" if result == 'error': www = 'www' nPos = s.find(www) if nPos == -1: s = 'www.' + s try: result = socket.gethostbyname(s) except: result = "error" wfile.write(s + ',' + result) wfile.write('\n') print s rfile.close() wfile.close()
转载于:https://www.cnblogs.com/fighter/archive/2012/06/28/2567529.html