Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.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.037 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '[0]': 0.09; 'operation,': 0.09; 'subject:error': 0.09; 'am,': 0.12; 'received:209.85.214.174': 0.13; '+short': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instance:': 0.16; 'inverse': 0.16; 'name)': 0.16; 'rotation': 0.16; 'wrote:': 0.18; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; '(and': 0.28; 'message-id:@mail.gmail.com': 0.28; 'order.': 0.29; 'usually': 0.31; 'quite': 0.32; 'list': 0.32; 'received:209.85.214': 0.32; 'tue,': 0.32; 'to:addr:python-list': 0.34; 'normally': 0.34; 'dns': 0.34; 'uses': 0.36; 'but': 0.37; 'list,': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'received:209.85': 0.38; 'getting': 0.38; 'being': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'address': 0.61; 'results': 0.63; '2012': 0.67; 'note:': 0.69; '(first)': 0.84; 'subject:( ': 0.84; 'canonical': 0.91; 'subject:skip:s 20': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=SW+nHTDOV49yOvvfDkhbYeTYALSr0vC7ItK1reeVHUI=; b=I49niywg6FImZ3LILsmM+Y3Nz0MBpdfkAIWLLq4O4XHW1aVPMQThjxOi3DPlZrdvEE 9L5n45MjE4FZnRM0VabGN2oxXr7a/tve0hMxbfTzT8CptbzrQJfY0OiEP7wko1jVTLdK KOyMab40D6B2SIEOB9B0+2lrfjTuBc1eqWo+Q= MIME-Version: 1.0 In-Reply-To: <4F0B6BBE.5090501@codeaurora.org> References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> <4F0B6BBE.5090501@codeaurora.org> Date: Tue, 10 Jan 2012 10:14:25 +1100 Subject: Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326150869 news.xs4all.nl 6916 [2001:888:2000:d::a6]:44055 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18715 On Tue, Jan 10, 2012 at 9:35 AM, Dominic Binks wrote: > The address database can have multiple names for the same IP address so > gethostbyaddr returns a list - [0] being the first item in the list (and > usually considered the canonical name) Point to note: The inverse operation, getting IP addresses from names, quite frequently returns multiple results - and in that case, there's no "canonical name". You'll still usually want to take the zeroth (first) item in the list, but often the list will change in order. Try, for instance: $ dig +short www.google.com which uses DNS rotation as a form of load-balancing. In any case, you normally just take the first entry. ChrisA