which outgoing network device/IP is used?

Steve Holden sholden at holdenweb.com
Wed Oct 9 19:02:04 EDT 2002


"Robert" <k.robert at gmx.de> wrote ...
>
> if a computer has more network devices I want to know which one (IP) is
used
> for a outgoing socket connection to a certain remote host. (in order to
> 'bind/accept' later on that IP for an incoming connection request)
>
> found only that socket.gethostbyname_ex(socket.gethostname()) provides a
> list of IPs
>
If the IP address you pass to the socket's binf is the null string it will
accept connections on *any* network interface. Is this what you mean?

Even listening on a single IP address you will have to verify the address of
the connecting system to be sure you are only accepting the conncetions you
want, so I don't imagine this would compromise any security requirements you
may have.

You should be able to find out the local address of a socket, whether
returned by an accept() call or by connect()ing to a remote server, by using
its getsockname() method. This returns an (IP, port#) tuple.

Hope this helps.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list