Transfer domain name to ip address in batch
Disadvantages: single thread
Purpose: if you have a local dns on the intranet, you can get the domain name, the intranet real ip.
#-*-coding=utf-8-*-# date: may 6, 2015 # author: sanr import socketdef ip (name): try: result = socket.getaddrinfo (name None) return result [0] [4] [0] except: return 0 if _ name__=='__main__': f = open ('url.txt') for line in f: print line.strip () +' + str (ip (line.rstrip () f.close ()
Or the following code mainly does not have to close the handle by itself
Import socketdef ip (name): try: result = socket.getaddrinfo (name, None) return result [0] [4] [0] except: return 0 if _ name__=='__main__': with open ('url.txt' 'r') as f: for line in f.readlines (): print line.strip () +'+ str (ip (line.rstrip ()