clowwindy
11 years ago
1 changed files with 73 additions and 0 deletions
@ -0,0 +1,73 @@ |
|||||
|
#!/usr/bin/env python |
||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
# Copyright (c) 2014 clowwindy |
||||
|
# |
||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
# of this software and associated documentation files (the "Software"), to deal |
||||
|
# in the Software without restriction, including without limitation the rights |
||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
# copies of the Software, and to permit persons to whom the Software is |
||||
|
# furnished to do so, subject to the following conditions: |
||||
|
# |
||||
|
# The above copyright notice and this permission notice shall be included in |
||||
|
# all copies or substantial portions of the Software. |
||||
|
# |
||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
# SOFTWARE. |
||||
|
|
||||
|
import socket |
||||
|
import struct |
||||
|
import common |
||||
|
|
||||
|
|
||||
|
_request_count = 1 |
||||
|
|
||||
|
# rfc1035 |
||||
|
# 1 1 1 1 1 1 |
||||
|
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
||||
|
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
||||
|
# | ID | |
||||
|
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
||||
|
# |QR| Opcode |AA|TC|RD|RA| Z | RCODE | |
||||
|
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
||||
|
# | QDCOUNT | |
||||
|
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
||||
|
# | ANCOUNT | |
||||
|
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
||||
|
# | NSCOUNT | |
||||
|
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
||||
|
# | ARCOUNT | |
||||
|
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
||||
|
|
||||
|
|
||||
|
def pack_request(address): |
||||
|
global _request_count |
||||
|
_request_count += 1 |
||||
|
header = struct.pack('!HBBHHHH', _request_count, 1, 0, 1, 0, 0, 0) |
||||
|
pass |
||||
|
|
||||
|
|
||||
|
def unpack_response(data): |
||||
|
# TODO detect address type |
||||
|
pass |
||||
|
|
||||
|
|
||||
|
def resolve(address, callback): |
||||
|
callback(address) |
||||
|
|
||||
|
|
||||
|
def test(): |
||||
|
def _callback(address): |
||||
|
print address |
||||
|
|
||||
|
resolve('www.baidu.com', _callback) |
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
test() |
Loading…
Reference in new issue