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

Chris Angelico rosuav at gmail.com
Tue Nov 26 23:56:13 CET 2013


On Wed, Nov 27, 2013 at 4:26 AM, Malte Forkel <malte.forkel at berlin.de> wrote:
> Thanks for the explanation. I guess I was hoping that I could use some
> property of a connection created with telnetlib or its socket to find
> out whether it was actually a host-local connection (i.e. a connection
> to 'localhost', '127.xx.xx.xx' or '<local_host_name>').
>
> So its either your initial suggestion of taking a hint from the user or
> comparing files on the server and the client.

You can still have a unique file, then; all you sacrifice is the
random name generation. And you can of course recognize 127.x.y.z as
local - it's just not the _only_ way to detect a local connection.

Since this is, presumably, an optimization, you could possibly just
tell people that it'll run faster if they tell it 127.0.0.1 than if
they tell it {whatever other IPs the server has}. That may end up
sufficient. Otherwise, yeah, detect by filesystem with a
manually-created file.

ChrisA



More information about the Python-list mailing list