Basic handling & forwarding with TCP requests #1071
-
Good morning, I've got a little problem with handling the TCP DNS requests with My basic script looks like so: LISTEN_HOST="0.0.0.0"
LISTEN_PORT="5353"
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((LISTEN_HOST, int(LISTEN_PORT)))
server_socket.listen()
while True:
conn, addr = server_socket.accept()
data = conn.recv(1024)
request = dns.message.from_wire(data)
conn.sendall(request.to_wire())
conn.close() How to parse TCP requests with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Take a look at this source for an example of how to do it. TCP is a byte stream, so messages are encoded as a two byte length and then the message content. First you read the length then you read that many bytes to get the message. |
Beta Was this translation helpful? Give feedback.
-
Alright, I have adapted that script to my code: import socket
import dns.query
import dns.message
LISTEN_HOST="0.0.0.0"
LISTEN_PORT="5353"
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((LISTEN_HOST, int(LISTEN_PORT)))
server_socket.listen()
while True:
conn, addr = server_socket.accept()
query = dns.query.receive_tcp(conn)
request = query[0] # same as from dns.message.from_wire()
dns.query.send_tcp(conn, request.to_wire())
conn.close() thank you again for help. |
Beta Was this translation helpful? Give feedback.
Take a look at this source for an example of how to do it. TCP is a byte stream, so messages are encoded as a two byte length and then the message content. First you read the length then you read that many bytes to get the message.