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?
CodePudding user response:
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("a\n".encode(),("192.168.1.100",37810))