|
1 | 1 | import getdns
|
2 |
| -import socket, fcntl, sys |
3 | 2 | from struct import pack, unpack
|
4 |
| - |
5 |
| - |
6 |
| -# |
7 |
| -# returns a tuple containing the network part of the ip |
8 |
| -# address for the interface and the netmask, both encoded |
9 |
| -# in strings. Definitely not portable to Windows, probably |
10 |
| -# not portable to some Unixes. Unfortunately you have |
11 |
| -# to pass in the name of the interface; interface name |
12 |
| -# will be discovered in a future version |
13 |
| -# |
14 |
| - |
15 |
| -def get_network_info(ifname): |
16 |
| - SIOCGIFADDR = 0x8915 |
17 |
| - SIOCGIFNETMASK = 0x891b |
18 |
| - |
19 |
| - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
20 |
| - netmask = fcntl.ioctl(s.fileno(), SIOCGIFNETMASK, pack('256s',ifname))[20:24] |
21 |
| - addr = fcntl.ioctl(s.fileno(), SIOCGIFADDR, pack('256s', ifname))[20:24] |
22 |
| - return (pack('!I', (unpack('!I', addr)[0] & unpack('!I', netmask)[0])), netmask) |
23 | 3 |
|
24 | 4 |
|
25 | 5 | def main():
|
26 | 6 | CLIENT_SUBNET_OPCODE = 8
|
27 |
| - LOCAL_INTERFACE = 'eth0' |
| 7 | + |
| 8 | + address = '192.168.1.0' |
28 | 9 | host = 'getdnsapi.net'
|
| 10 | + source_len = 12 |
29 | 11 |
|
30 |
| - if len(sys.argv) == 2: |
31 |
| - host = sys.argv[1] |
32 | 12 | family = pack("!H", 1) # start building the edns option fields
|
33 |
| - source_netmask, address = get_network_info(LOCAL_INTERFACE) |
34 |
| - scope_netmask = pack("B", 0) |
| 13 | + source_len = pack('!B', source_len) |
| 14 | + scope_len = pack('!B', 0) |
35 | 15 |
|
36 | 16 | #
|
37 | 17 | # encoding the binary data in strings makes it really easy
|
38 | 18 | # to build packets by concatenating those strings
|
39 | 19 | #
|
40 |
| - payload = family + source_netmask + scope_netmask + address |
41 |
| - length = pack("!H", len(payload)) |
| 20 | + address = pack('!BBBB', 192, 168, 1, 0) |
| 21 | + payload = family + source_len + scope_len + address |
42 | 22 | ext = { 'add_opt_parameters': {'options':
|
43 | 23 | [ {'option_code': CLIENT_SUBNET_OPCODE,
|
44 |
| - 'option_data': length+payload} ] }} |
| 24 | + 'option_data': payload} ] }} |
45 | 25 |
|
46 | 26 | c = getdns.Context()
|
47 | 27 | c.resolution_type = getdns.RESOLUTION_STUB
|
|
0 commit comments