-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_example.py
More file actions
38 lines (27 loc) · 1.16 KB
/
Copy pathclient_example.py
File metadata and controls
38 lines (27 loc) · 1.16 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
37
38
import logging
import socket
logging.basicConfig(format='%(asctime)s \n%(message)s', level=logging.INFO)
def run_client():
while True:
print("Write your question at format: dig DOMAIN.NAME @local_server")
print("Write END to close connection")
server_address = ('127.0.0.7', 53)
try:
input_question = input()
input_question_splited = input_question.split()
if input_question == "END":
break
if (len(input_question_splited)
!= 3 or input_question_splited[0] != "dig" or '.' not in input_question_splited[1]):
raise IndexError
logging.info("Sending DNS-query...")
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
sock.sendto(input_question.encode(), server_address)
response, _ = sock.recvfrom(512)
print(response.decode())
except IndexError:
logging.error("Incorrect format of question")
continue
if __name__ == "__main__":
run_client()
# ['77.88.55.242', '5.255.255.242', '77.88.44.242']