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

Malte Forkel malte.forkel at berlin.de
Tue Nov 26 06:26:47 EST 2013


Am 26.11.2013 00:41, schrieb Ben Finney:
> 
> 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.
> 
>     <URL:https://en.wikipedia.org/wiki/Localhost>
>     <URL:https://en.wikipedia.org/wiki/Unix_domain_socket>
> 
> 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.
> 

Unfortunately, I can't rely on the user to use a specific way to specify
the (local) host. Therefor, the application has to detect if it is run
on the same host as the server.

May be my description was incomplete and somewhat misleading. Let me try
to provide more information.

The server is running on a Linux host. The application might be run on
any Windows or Linux host in the (local) network. When starting the
application, the user can specify the server by host and and a port. If
no host is specified, it defaults to localhost. If no port is specified,
a couple of well known ports are tried. The application establishes the
connection to the server using telnetlib.

Most of the application's functionality uses the telnet connection to
communicate with the server. One special operation is not available in
the protocol, but can be implemented by a direct file-based operation if
the application is run on the server itself. I would like to use that
option if technically feasible.

Malte




More information about the Python-list mailing list