Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18719
| From | Nick Dokos <nicholas.dokos@hp.com> |
|---|---|
| Subject | Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error |
| References | (4 earlier) <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> <roy-4CE54B.15314102012012@news.panix.com> <f683b8f4-3a59-4c9f-94ef-82a9017dcd31@m20g2000vbf.googlegroups.com> <4F0B6BBE.5090501@codeaurora.org> <CAPTjJmp06is_WZv9BRatTvS4Y-=sfGNeL-1k3VZSTQerYYzCVQ@mail.gmail.com> |
| Organization | HPCS |
| Date | 2012-01-09 18:32 -0500 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4558.1326152352.27778.python-list@python.org> (permalink) |
Chris Angelico <rosuav@gmail.com> wrote: > On Tue, Jan 10, 2012 at 9:35 AM, Dominic Binks <dbinks@codeaurora.org> 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. > On both 2.6.6 and 2.7.1, the doc says: ,---- | >>> help(socket.gethostbyaddr) | Help on built-in function gethostbyaddr in module _socket: | | gethostbyaddr(...) | gethostbyaddr(host) -> (name, aliaslist, addresslist) | | Return the true host name, a list of aliases, and a list of IP addresses, | for a host. The host argument is a string giving a host name or IP number. `---- so socket.gethostbyaddr(os.environ['REMOTE_ADDR'])[0] is the 0th element of the tuple, i.e. the *name* that is returned. So (unless I'm confused which is always a distinct possibility) this has nothing to do with load-balancing or multiple addresses: it's the equivalent of dig +short -x <addr> Nick
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-01-02 16:49 +0100
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 10:18 -0800
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Roy Smith <roy@panix.com> - 2012-01-02 13:42 -0500
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 11:51 -0800
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Roy Smith <roy@panix.com> - 2012-01-02 15:31 -0500
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-09 14:19 -0800
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Dominic Binks <dbinks@codeaurora.org> - 2012-01-09 14:35 -0800
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-09 15:04 -0800
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-01-10 07:42 +0100
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Chris Angelico <rosuav@gmail.com> - 2012-01-10 18:29 +1100
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Chris Angelico <rosuav@gmail.com> - 2012-01-10 10:14 +1100
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Nick Dokos <nicholas.dokos@hp.com> - 2012-01-09 18:32 -0500
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Chris Angelico <rosuav@gmail.com> - 2012-01-10 13:08 +1100
Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-02 11:54 -0800
csiph-web