当前位置: 首页>>代码示例>>Python>>正文


Python Resolver.gethostbyname方法代码示例

本文整理汇总了Python中dns.resolver.Resolver.gethostbyname方法的典型用法代码示例。如果您正苦于以下问题:Python Resolver.gethostbyname方法的具体用法?Python Resolver.gethostbyname怎么用?Python Resolver.gethostbyname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dns.resolver.Resolver的用法示例。


在下文中一共展示了Resolver.gethostbyname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import gethostbyname [as 别名]
 def run(self):
     """ Run the handler thread """
     print "*Ping* We've got a message!"
     # Handle DNS request
     resolver = Resolver(self.caching, self.ttl)
     aliasRecords = []
     addressRecords = []
     # Read and resolve the questions one-by-one
     questions = self.request.questions
     for question in questions:
         hostname = question.qname
         (hostname, aliases, addresses) = resolver.gethostbyname(hostname)
         
         for alias in aliases:
             aliasData = dns.resource.RecordData.create(Type.CNAME, alias)
             aliasRecord = dns.resource.ResourceRecord(hostname, Type.CNAME, Class.IN, 9001, aliasData) # TODO fix ttl
             aliasRecords.append(aliasRecord)
         for address in addresses:
             addressData = dns.resource.RecordData.create(Type.A, address)
             addressRecord = dns.resource.ResourceRecord(hostname, Type.A, Class.IN, 9001, addressData)
             addressRecords.append(addressRecord)
         
     # Crafting of the response
     respHeader = self.request.header
     respHeader.qr = 1
     respHeader.qd_count = 0
     respHeader.an_count = 1
     
     respMessage = dns.message.Message(respHeader, [], addressRecords + aliasRecords, [], [])
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     respMessageByte = respMessage.to_bytes()
     sock.sendto(respMessageByte, self.clientAddr)
     print "Ended request: " + hostname
     sock.close()
开发者ID:gitLabor8,项目名称:proj2_s4368312_s4384873,代码行数:36,代码来源:server.py


注:本文中的dns.resolver.Resolver.gethostbyname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。