-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
38 lines (28 loc) · 1.3 KB
/
Copy pathclient.py
File metadata and controls
38 lines (28 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import socket
from parser.constants import RecordTypes
from parser.parsers import parse_answers
from parser.common_parsers import str_to_hex, domain_to_bytes_str
import argparse
def insert_info_into_request(domain, q_type):
return "4a 4a 01 00 00 01 00 00 00 00 00 00 {} 00 {} 00 01".format(domain_to_bytes_str(domain),
RecordTypes.get_hex_str_form_str(q_type))
class Client:
def __init__(self, q_name, q_type):
if q_type not in RecordTypes.ValidRequestType:
raise ValueError("Invalid type value")
self.data = str_to_hex(insert_info_into_request(q_name, q_type))
self.address = "127.0.0.1"
self.port = 53
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.sendto(self.data, (self.address, self.port))
data, sender = s.recvfrom(256)
answer = parse_answers(data)
print(answer)
def main():
parser = argparse.ArgumentParser(description='Client for cash dns')
parser.add_argument("domain", help="domain that you search")
parser.add_argument("type", default="A", help="Type of record that you search (A, AAAA, NS, TXT, MX)")
args = parser.parse_args()
Client(args.domain, args.type)
if __name__ == "__main__":
main()