1. DNS/実装/python/dnslib


From Version 0.9.12 the master repository for _dnslib_ has been moved to

A library to encode/decode DNS wire-format packets supporting both Python 2.7 and Python 3.2+.



例外処理: https://docs.python.org/ja/3/library/exceptions.html


forked from andreif/Simple DNS server (UDP and TCP) in Python using dnslib.py

https://github.com/paulc/dnslib /0.9.14


1.1. DNS/実装/python/dnslib


dig response形式だけでなく、python tableでもレコードを扱える。



使用例:/usage /example /BaseResolver class


/ゾーンサーバー /リゾルバー /client.py /intercept.py


1.2. Classes

The key DNS packet handling classes are in dnslib.dns and map to the
standard DNS packet sections:

* DNSRecord - container for DNS packet. Contains:
- DNSHeader
- Question section containing zero or more DNSQuestion objects
- Answer section containing zero or more RR objects
- Authority section containing zero or more RR objects
- Additional section containing zero or more RR objects
* DNS RRs (resource records) contain an RR header and an RD object)
* Specific RD types are implemented as subclasses of RD
* DNS labels are represented by a DNSLabel class - in most cases
this handles conversion to/from textual representation however
does support arbitatry labels via a tuple of bytes objects


1.3. install

ubuntu setup.py install -- ToshinoriMaeno 2016-07-16 08:38:41

creating build/bdist.linux-x86_64/egg/EGG-INFO
copying dnslib.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dnslib.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dnslib.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dnslib.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
dnslib.test_decode: module references __file__
creating dist
creating 'dist/dnslib-0.9.6-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing dnslib-0.9.6-py2.7.egg
creating /usr/local/lib/python2.7/dist-packages/dnslib-0.9.6-py2.7.egg
Extracting dnslib-0.9.6-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adding dnslib 0.9.6 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/dnslib-0.9.6-py2.7.egg
Processing dependencies for dnslib==0.9.6
Finished processing dependencies for dnslib==0.9.6

1.4. Simple


$ python Simple\ DNS\ server\ \(UDP\ and\ TCP\)\ in\ Python\ using\ dnslib.py

Starting nameserver...
UDP server loop running in thread: Thread-1
TCP server loop running in thread: Thread-2

reply.add_ns はなくなっていた。add_authになったらしい。

__init__.py:    passed to add_answer/add_auth/add_ar etc)
digparser.py:        sect_map = {'a':'add_answer','auth':'add_auth','ar':'add_ar'}

dns.py:        >>> d.add_auth(RR("abc.com",QTYPE.SOA,ttl=60,rdata=SOA("ns.abc.com","admin.abc.com",(20140101,3600,3600,3600,3600))))
dns.py:    def add_auth(self,*auth):
dns.py:            >>> a.add_auth(*RR.fromZone("abc.com 3600 NS nsa.abc.com"))

Moin2Qmail: DNS/実装/python/dnslib (last edited 2021-03-06 12:01:39 by ToshinoriMaeno)