Binding to specific IP addresses
donn at u.washington.edu
Thu Aug 23 19:15:50 CEST 2001
Quoth "Graham Ashton" <graz at mindless.com>:
| The lsof program tells me that the process that is using the address is
| my dial up software, pppd. I find this very surprising as the 192.168.5.1
| address is the address of my ethernet card and has nothing to do with my
| dial up connection.
| Can anybody shed some light on this for me? Is there something that I
| ought to be doing to avoid listening on other interfaces?
Your Python program is OK, problem seems to be ppp. You can bind to
a specific IP and its interface, but only if nothing else is already
bound. The following program successfully binds to the same port on
separate IP addresses and receives connections on the associated IP.
If it doesn't for you, then there's some problem with your platform -
but I assume you're running some kind of UNIX, given that you have
"lsof", and I find that even Linux gets this right.
If that checks out and lsof is right, then ppp bound to INADDR_ANY or
directly to this interface for some reason, and you can't have it.
If lsof shows it bound to *:port, then it bound to INADDR_ANY; if
it bound directly, you'll see address:port.
Donn Cave, donn at u.washington.edu
sf = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sf.bind(('100.100.100.100', 7017)) # substitute real IP 1.
sb = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sb.bind(('18.104.22.168', 7017)) # substitute real IP 2.
More information about the Python-list