温馨提示×

python如何绑定域名解析

九三
601
2021-01-30 19:04:48
栏目: 云计算

python如何绑定域名解析

python中实现单线程绑定域名解析,具体方法如下:

import time

import socket

def ReadHost(file):

  hosts=[]

  ...

  return hosts

def SynResolve(fr):

  hosts=ReadHost(fr)

  IPs={}

  for host in hosts:

  try:

   results=socket.getaddrinfo(host,None)

  for result in results:

  print host, result[4][0]

    IPs[result[4][0]]=host

  except Exception,e:

   print e

  file.close()

if __name__=='__main__':

  start=time.time()

  print 'starting at: ',start

  SynResolve('host')

  print 'ending at: ',time.time()-start

0