socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

Chris Angelico rosuav at gmail.com
Mon Jan 9 18:14:25 EST 2012


On Tue, Jan 10, 2012 at 9:35 AM, Dominic Binks <dbinks at 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.

ChrisA



More information about the Python-list mailing list