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

Walter Hurry walterhurry at lavabit.com
Tue Nov 26 18:08:04 EST 2013


On Wed, 27 Nov 2013 09:56:13 +1100, Chris Angelico wrote:

> 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.

How about checking the MAC address of the local network card on the 
client, and then comparing that against a file on the server?

Easy enough with ifconfig and grep. I presume that there is also a way on 
Windows, but others will have to contribute that.



More information about the Python-list mailing list