def send_tcp(data, host, port):
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.connect((host, port))
 sock.sendall(data)
 response = sock.recv(8192)
 length = struct.unpack('!H', bytes(response[:2]))[0]
 while ((len(response) - 2) < length):
  response += sock.recv(8192)
 sock.close()
 return response

def send_tcp ( data , host , port ) : sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) sock . connect ( ( host , port ) ) sock . sendall ( data ) response = sock . recv ( 8192 ) length = struct . unpack ( '!H' , bytes ( response [ : 2 ] ) ) [ 0 ] while ( ( len ( response ) - 2 ) < length ) : response += sock . recv ( 8192 ) sock . close ( ) return response
helper function to send/receive dns tcp request .