ネットワーク ************** Contents: .. contents:: .. toctree:: :maxdepth: 1 DNS系のオペレーション ============================ http://sourceforge.net/projects/pydns/ から、 sudo easy_install pydns :: >>> import DNS >>> Dns.defaults {'rd': 1, 'protocol': 'udp', 'timeout': 30, 'timing': 1, 'opcode': 0, 'server_rotate': 0, 'qtype': 1, 'port': 53, 'server': []} >>> Req = DNS.Request(qtype="A", server="8.8.8.8") >>> Res = req.req(name="www.google.com") >>> res.show() (digの出力) ;; ANSWERS: www.google.com 86399 CNAME www.l.google.com www.l.google.com 299 A 74.125.235.81 www.l.google.com 299 A 74.125.235.84 www.l.google.com 299 A 74.125.235.80 www.l.google.com 299 A 74.125.235.83 www.l.google.com 299 A 74.125.235.82 >>> res.header {'aa': 0, 'status': 'NOERROR', 'qr': 1, 'nscount': 0, 'opcodestr': 'QUERY', 'qdcount': 1, 'tc': 0, 'rd': 1, 'arcount': 0, 'opcode': 0, 'ra': 1, 'z': 0, 'rcode': 0, 'id': 62156, 'ancount': 6} >>> res.answers [{'name': 'www.google.com', 'data': 'www.l.google.com', 'typename': 'CNAME', 'classstr': 'IN', 'ttl': 86399, 'type': 5, 'class': 1, 'rdlength': 8}, {'name': 'www.l.google.com', 'data': '74.125.235.81', 'typename': 'A', 'classstr': 'IN', 'ttl': 299, 'type': 1, 'class': 1, 'rdlength': 4}, {'name': 'www.l.google.com', 'data': '74.125.235.84', 'typename': 'A', 'classstr': 'IN', 'ttl': 299, 'type': 1, 'class': 1, 'rdlength': 4}, {'name': 'www.l.google.com', 'data': '74.125.235.80', 'typename': 'A', 'classstr': 'IN', 'ttl': 299, 'type': 1, 'class': 1, 'rdlength': 4}, {'name': 'www.l.google.com', 'data': '74.125.235.83', 'typename': 'A', 'classstr': 'IN', 'ttl': 299, 'type': 1, 'class': 1, 'rdlength': 4}, {'name': 'www.l.google.com', 'data': '74.125.235.82', 'typename': 'A', 'classstr': 'IN', 'ttl': 299, 'type': 1, 'class': 1, 'rdlength': 4}] GeoIP =============== http://www.maxmind.com/app/python より :: sudo easy_install pygeoip wget http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz wget http://www.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz sudo easy_install pygeoip >>> import pygeoip >>> gi = pygeoip.GeoIP('/Users/kanai/usr/GeoLiteCity.dat') >>> gi.country_code_by_addr('8.8.8.8') 'US' >>> gi.country_name_by_addr('8.8.8.8') 'United States' >>> gi = pygeoip.GeoIP('/Users/kanai/usr/GeoIPASNum.dat') >>> gi.org_by_addr('203.178.143.70') u'AS2500 WIDE Project'