= DNS/実装/python/dnslib = <> https://pypi.org/project/dnslib/ From Version 0.9.12 the master repository for _dnslib_ has been moved to GitHub (https://github.com/paulc/dnslib). ---- A library to encode/decode DNS wire-format packets supporting both Python 2.7 and Python 3.2+. DNS関連の構造、動作を勉強するのにもってこいのライブラリだ。 python 利用者にはお勧め。-- ToshinoriMaeno <> [[/lame_check]] 例外処理: https://docs.python.org/ja/3/library/exceptions.html ---- [[/README]] forked from andreif/Simple DNS server (UDP and TCP) in Python using dnslib.py https://github.com/paulc/dnslib [[/0.9.14]] https://pypi.org/project/dnslib/ From Version 0.9.12 the master repository for dnslib has been moved to GitHub <> == DNS/実装/python/dnslib == pythonでDNS関係の処理、サーバー作成をするのに便利。 dig response形式だけでなく、python tableでもレコードを扱える。 phishing目的の返答をするゾーンサーバーを作るための道具としても使える。  脆弱性が疑われるリゾルバーをテストするのに必要となる。 https://pypi.org/project/dnslib/ 使用例:[[/usage]] [[/example]] [[/BaseResolver]] class サーバ例:[[/sample-resolver]] Resource Recordがただのlistでは使い勝手がよくない。  実装にあわせて、構成する。 -- ToshinoriMaeno <> [[/ゾーンサーバー]] [[/リゾルバー]] [[/client.py]] [[/intercept.py]] [[/問い合わせ]] == 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 }}} [[/DNSHeader]] == install == ubuntu setup.py install -- ToshinoriMaeno <> {{{ 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 }}} == Simple == https://gist.github.com/andreif/6069838 $ 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")) }}}