I need help with sockets in python. A device (D) is directly connected via an Ethernet cable to an USB-to-Ehternet adpater (eth1) plugged into a Raspberry Pi. ifconfig
and running sudo tcpdump -i eth1
show that D is communicating under IP address 169.254.129.33. When I run following code in Python, I don't receive a reply from D, although the message sent is said to trigger a response.
import socket
HOST = socket.gethostbyname(socket.gethostname())
PORT = 30444
D_IP = '169.254.129.33'
msg = 'Calling all IRC devices'
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.sendto(msg.encode(), (D_IP, PORT))
data, address = s.recvfrom(PORT)
s.close()
print(address, ' replied: ', data.decode())
It seems like Python is either not sending msg
via the adapter to D or D's IP address is not the one I thought it was.
How can I tell python to specifically use the USB-to-Ethernet adapter for UDP communication? How do I get the correct IP address of D when attached to the Pi and not to a router?
P.S.: Hope, the formatting is okay and my English isn't too bad.