Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What host to use when making a UDP socket in python?

I want ro receive some data that is sent as a UDP packet over VPN. So wrote (mostly copied) this program in python:

import socket
import sys

HOST = ??????? 
PORT = 80


# SOCK_DGRAM is the socket type to use for UDP sockets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

sock.bind((HOST,PORT))
data,addr = sock.recv(1024)
print "Received: %s" % data
print "Addr: %s" % addr 

What should I use as host? I know the IP of the sender but it seems anything thats not local gives me socket.error: [Errno 10049]. The IP that the VPN gives me (the same IP that the sender sends to, that is)? Or just localhost?

like image 486
c0m4 Avatar asked Dec 05 '22 06:12

c0m4


1 Answers

The host argument is the host IP you want to bind to. Specify the IP of one of your interfaces (Eg, your public IP, or 127.0.0.1 for localhost), or use 0.0.0.0 to bind to all interfaces. If you bind to a specific interface, your service will only be available on that interface - for example, if you want to run something that can only be accessed via localhost, or if you have multiple IPs and need to run different servers on each.

like image 103
Nick Johnson Avatar answered Dec 08 '22 14:12

Nick Johnson