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

Malte Forkel malte.forkel at berlin.de
Tue Nov 26 12:26:20 EST 2013


Am 26.11.2013 13:26, schrieb Chris Angelico:
> If you deliberately create a file with a random name, the chances of
> one existing with the same name on the client are infinitesimal unless
> someone's deliberately trying to confuse things... in which case I
> wouldn't worry about it.
> 
I wouldn't, either. But the server is an existing application that I
can't extend. It does not support creating a file with a random name.

> No, because there's no such thing as a "local connection". For
> instance, I have two internet connections at my house, and I can
> telnet out on one of them and back in on the other - but both
> connections are NATted, so the machine itself doesn't have an IP that
> matches what I'm talking about here. I could have a socket connection
> from w.x.y.z port 12345 to a.b.c.d port 80, and there's no way
> telnetlib would recognize that as coming back to the same computer,
> because this computer's IP addresses are all RFC 1918 ones (127.0.0.1,
> 192.168.0.19, 192.168.2.2).
>
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.





More information about the Python-list mailing list