Send UDP package via python not getting response

Question:

I have a security camera that receive any data via UDP port 37810 and respond with a JSON. The camera ip is 192.168.1.100

echo 'a' |nc -u  192.168.1.100 37810 

response:

DHIP??{"mac":"18:0d:2c:d1:a2:29","method":"client.notifyDevInfo","params":{"deviceInfo":{"AlarmInputChannels":0,"AlarmOutputChannels":0,"DeviceClass":"MHDX","DeviceType":"MHDX 3116","Find":"BD","HttpPort":88,"IPv4Address":{"DefaultGateway":"192.168.1.1","DhcpEnable":false,"IPAddress":"192.168.1.100","SubnetMask":"255.255.255.0"},"IPv6Address":{"DefaultGateway":"","DhcpEnable":true,"IPAddress":"/64","LinkLocalAddress":"fe80::1a0d:2cff:fed1:a229/64"},"Init":3238,"MachineName":"MHDX","Manufacturer":"Intelbras","Port":57777,"RemoteVideoInputChannels":0,"SerialNo":"EKHH2502545HM","Vendor":"Intelbras","Version":"4.000.00IB002.17","VideoInputChannels":16,"VideoOutputChannels":0}}}

I can confirm with tcpdump that the message was sent and the camera responded:

IP 192.168.0.105.56613 > 192.168.1.100.37810: UDP, length 2
IP 192.168.1.100.37810 > 192.168.0.105.53256: UDP, length 712

Then I wrote a simple python3 program to do the same:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,socket.IPPROTO_UDP)
s.sendto("a".encode(),("192.168.1.100",37810))

tcpdump show the that the "message" was sent, but the camera never responded.

IP 192.168.0.105.53792 > 192.168.1.100.37810: UDP, length 1

I know that this python script is not listening for incoming data, but the camera should have answered and tcpdump should have shown
What am I missing?

Asked By: Rodrigo Gusso

||

Answers:

echo adds a newline to the output by default. I guess the camera is waiting for the newline to indicate the end of the request, so you need to send that in Python as well.

s.sendto("an".encode(),("192.168.1.100",37810))
Answered By: Barmar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.