Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'url:pypi': 0.03; 'package,': 0.03; 'interfaces': 0.04; 'languages.': 0.04; 'output': 0.05; 'explicit': 0.07; 'postgresql': 0.07; 'socket': 0.07; 'strict': 0.07; 'subject:same': 0.07; 'debugging.': 0.09; 'indication': 0.09; 'method:': 0.09; 'postgresql,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tcp/ip': 0.09; 'subject:How': 0.10; 'python': 0.11; "wouldn't": 0.14; 'windows': 0.15; 'doing),': 0.16; 'filesystem': 0.16; 'implies': 0.16; 'inclined': 0.16; 'normal,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'tcp': 0.16; 'do,': 0.16; 'app': 0.19; 'module': 0.19; 'normally': 0.19; 'solution.': 0.20; 'seems': 0.21; 'platforms': 0.22; 'install': 0.23; 'header:User- Agent:1': 0.23; "aren't": 0.24; 'instance,': 0.24; 'of.': 0.24; 'parse': 0.24; 'specify': 0.24; 'equivalent': 0.26; 'extension': 0.26; 'possibly': 0.26; 'query': 0.26; '(for': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'unix': 0.29; "i'm": 0.30; '(which': 0.31; 'easier': 0.31; 'this.': 0.32; 'run': 0.32; '(including': 0.33; 'url:python': 0.33; 'running': 0.33; 'core': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'module.': 0.36; 'method': 0.36; 'thanks': 0.36; 'possible': 0.36; 'url:org': 0.36; 'application': 0.37; 'too': 0.37; 'two': 0.37; 'list.': 0.37; 'server': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'anything': 0.39; 'environment.': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'easy': 0.60; 'signal': 0.60; 'simply': 0.61; "you're": 0.61; 'address': 0.63; 'name': 0.63; 'direct': 0.67; 'received:93': 0.72; 'one).': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Malte Forkel Subject: Re: How to determine whether client and server are on the same host Date: Tue, 26 Nov 2013 12:23:49 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: p5ddb24f4.dip0.t-ipconnect.de User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385465037 news.xs4all.nl 15998 [2001:888:2000:d::a6]:45891 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60499 Am 26.11.2013 00:07, schrieb Chris Angelico: > > Two easy ways you could do this. I would be inclined to do what > PostgreSQL and others do, and have an explicit indication that you > want to use a local method: for instance, the name "localhost". Use of > anything else (including "127.0.0.1") means you use TCP/IP as normal, > but the strict word "localhost", which is normally equivalent to the > address 127.0.0.1, would signal your app to use the direct method (for > PostgreSQL, that's a Unix socket rather than a TCP one). This means > you can still force telnet to be used even if you're working locally - > good for debugging. > Unfortunately, I can't rely on the user to use a specific way to specify the (local) host. > Alternatively, you can simply query the current network interfaces for > their IPs, and see if the IP you were given is in that list. I don't > know of a way to do that in core Python, but the C function you need > is getifaddrs(), and this claims to wrap all that up nicely: > > https://pypi.python.org/pypi/netifaces > > This method would detect, for instance, that calling up 192.168.0.19 > port 12345 is a local lookup, because eth0 has address 192.168.0.19, > and that 192.168.2.2 port 54321 is local too, because wlan0 has > address 192.168.2.2. > That's a very nice module which I wasn't aware of. But if possible I wouldn't want to force the user to install a (binary) extension module. Finding the right module for his platform and version of Python might be too difficult. > If you aren't too concerned with running this on multiple platforms > (which seems likely - working with the local filesystem implies you > know a lot about what the server and client are doing), you could > simply parse the output of 'ip addr', 'ipconfig', 'ifconfig', or some > equivalent network utility for your platform. That might be easier > than playing with the package, depending on environment. > The application is run under Windows as well. So I'd have to parse the output of other network utilities as well, possibly in a variety of languages. Thanks for your suggestions! I'm sorry I'm so picky. May be there just is no easy solution. Malte