How to determine whether client and server are on the same host

Ben Finney ben+python at
Tue Nov 26 00:41:44 CET 2013

Malte Forkel <malte.forkel at> writes:

> I have a Python application that communicates with a server via
> telnet. Host and port of the server are supplied by the user when the
> application is started.
> How can I determine from within the application whether the server's
> host actually is the local host? (In that case I could implement an
> operation not available in the telnet-based protocol by directly
> accessing the local filesystem.)

On Unix, this is up to the person invoking the program: the “sockets
facility allows for a host-local connection to appear as though it's
going over a network.


In other words: Your program shouldn't go snooping around to
second-guess the connection type; if the user asked for a TCP/IP
connection, that's what they should get. If they want to take advantage
of a local connection, they can use a Unix domain socket.

 \     “I wrote a song, but I can't read music so I don't know what it |
  `\    is. Every once in a while I'll be listening to the radio and I |
_o__)        say, ‘I think I might have written that.’” —Steven Wright |
Ben Finney

More information about the Python-list mailing list