Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18331 > unrolled thread

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

Started byThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
First post2012-01-02 16:49 +0100
Last post2012-01-02 11:54 -0800
Articles 14 — 6 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#18331 — Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-01-02 16:49 +0100
SubjectRe: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error
Message-ID<jdsjld$mau$1@r03.glglgl.gl>
Am 22.12.2011 15:40 schrieb Νικόλαος Κούρας:
> Hello when i try to visit my webpage i get the error it displays. Iam
> not posting it since you can see it by visiting my webpage at
> http://superhost.gr
>
> Please if you can tell me what might be wrong.

What is wrong on this site? Mainly the unwanted sound.

Are you trying to sell something? Then you should try not to scare your 
potential customers away.

[toc] | [next] | [standalone]


#18337

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 10:18 -0800
Message-ID<bacea15d-fae0-4b1f-8a8e-a8b06b561fc0@t30g2000vbx.googlegroups.com>
In reply to#18331
On 2 Ιαν, 17:49, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
a470-7603bd3aa...@spamschutz.glglgl.de> wrote:
> Am 22.12.2011 15:40 schrieb Νικόλαος Κούρας:
>
> > Hello when i try to visit my webpage i get the error it displays. Iam
> > not posting it since you can see it by visiting my webpage at
> >http://superhost.gr
>
> > Please if you can tell me what might be wrong.
>
> What is wrong on this site? Mainly the unwanted sound.
>
> Are you trying to sell something? Then you should try not to scare your
> potential customers away.

I'am trying to present myself through my webpage as computer tech.
Is the background music so bad?! :-)

[toc] | [prev] | [next] | [standalone]


#18339

FromRoy Smith <roy@panix.com>
Date2012-01-02 13:42 -0500
Message-ID<roy-F4BA5C.13424802012012@news.panix.com>
In reply to#18337
In article 
<bacea15d-fae0-4b1f-8a8e-a8b06b561fc0@t30g2000vbx.googlegroups.com>,
 ÉΪɫɻόλαος Κούρας <nikos.kouras@gmail.com> wrote:

> I'am trying to present myself through my webpage as computer tech.
> Is the background music so bad?! :-)

Yes.  Background music on web sites is evil.

[toc] | [prev] | [next] | [standalone]


#18345

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 11:51 -0800
Message-ID<24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com>
In reply to#18339
On 2 Ιαν, 20:42, Roy Smith <r...@panix.com> wrote:
> In article
> <bacea15d-fae0-4b1f-8a8e-a8b06b561...@t30g2000vbx.googlegroups.com>,
>  ÉΪɫɻόλαος Κούρας <nikos.kou...@gmail.com> wrote:
>
> > I'am trying to present myself through my webpage as computer tech.
> > Is the background music so bad?! :-)
>
> Yes.  Background music on web sites is evil.

Evil?!?! How come? :)

[toc] | [prev] | [next] | [standalone]


#18347

FromRoy Smith <roy@panix.com>
Date2012-01-02 15:31 -0500
Message-ID<roy-4CE54B.15314102012012@news.panix.com>
In reply to#18345
In article 
<24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com>,
 ÉΪɫɻόλαος Κούρας <nikos.kouras@gmail.com> wrote:

> On 2 ÉßÉΩÉΥ, 20:42, Roy Smith <r...@panix.com> wrote:
> > In article
> > <bacea15d-fae0-4b1f-8a8e-a8b06b561...@t30g2000vbx.googlegroups.com>,
> > †ÉΪɫɻόλαος Κούρας <nikos.kou...@gmail.com> wrote:
> >
> > > I'am trying to present myself through my webpage as computer tech.
> > > Is the background music so bad?! :-)
> >
> > Yes.  Background music on web sites is evil.
> 
> Evil?!?! How come? :)

Because people hate going to web sites and having background music start 
to play.  But, there are better fora than here for discussions of web 
site best practices.

[toc] | [prev] | [next] | [standalone]


#18712

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-09 14:19 -0800
Message-ID<f683b8f4-3a59-4c9f-94ef-82a9017dcd31@m20g2000vbf.googlegroups.com>
In reply to#18347
Can you please explain me what the [0] in host =
socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?

Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
instead? what is the need of [0] ?

[toc] | [prev] | [next] | [standalone]


#18713

FromDominic Binks <dbinks@codeaurora.org>
Date2012-01-09 14:35 -0800
Message-ID<mailman.4552.1326148616.27778.python-list@python.org>
In reply to#18712
On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote:
> Can you please explain me what the [0] in host =
> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?
>
> Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
> instead? what is the need of [0] ?

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)

-- 
Dominic Binks: dbinks@codeaurora.org
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum

[toc] | [prev] | [next] | [standalone]


#18714

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-09 15:04 -0800
Message-ID<1e0e10e9-263f-4fde-8cdd-ece561c2c5fd@w4g2000vbc.googlegroups.com>
In reply to#18713
On 10 Ιαν, 00:35, Dominic Binks <dbi...@codeaurora.org> wrote:
> On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote:
>
> > Can you please explain me what the [0] in host =
> > socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?
>
> > Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
> > instead? what is the need of [0] ?
>
> 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)

Thank you!

[toc] | [prev] | [next] | [standalone]


#18738

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-01-10 07:42 +0100
Message-ID<jegmkb$bl8$1@r03.glglgl.gl>
In reply to#18713
Am 09.01.2012 23:35 schrieb Dominic Binks:
> On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote:
>> Can you please explain me what the [0] in host =
>> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end?
>>
>> Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
>> instead? what is the need of [0] ?
>
> 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)

It might be noteworthy that it is nowadays preferrable to use 
getaddrinfo() instead. This way, you get all acceptable IP addresses, 
not only IPv4 ones. And then, you should not only try this one entry - 
[0] -, but iterate over all of them until you have a connection.

BTW: This behaviour might be useful with gethostbyaddr() as well - if 
the first one returned has gone away, you have the chance to reach the 
2nd one...


Thomas

[toc] | [prev] | [next] | [standalone]


#18739

FromChris Angelico <rosuav@gmail.com>
Date2012-01-10 18:29 +1100
Message-ID<mailman.4583.1326180571.27778.python-list@python.org>
In reply to#18738
On Tue, Jan 10, 2012 at 5:42 PM, Thomas Rachel
<nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
wrote:
> BTW: This behaviour might be useful with gethostbyaddr() as well - if the
> first one returned has gone away, you have the chance to reach the 2nd
> one...

In its directest sense, probably not. All you're getting is multiple
names for the same IP address. But if some of those names resolve to
multiple IP addresses, then it's entirely possible that what you say
is so.

ChrisA

[toc] | [prev] | [next] | [standalone]


#18715

FromChris Angelico <rosuav@gmail.com>
Date2012-01-10 10:14 +1100
Message-ID<mailman.4554.1326150869.27778.python-list@python.org>
In reply to#18712
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.

ChrisA

[toc] | [prev] | [next] | [standalone]


#18719

FromNick Dokos <nicholas.dokos@hp.com>
Date2012-01-09 18:32 -0500
Message-ID<mailman.4558.1326152352.27778.python-list@python.org>
In reply to#18712
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

[toc] | [prev] | [next] | [standalone]


#18728

FromChris Angelico <rosuav@gmail.com>
Date2012-01-10 13:08 +1100
Message-ID<mailman.4570.1326161318.27778.python-list@python.org>
In reply to#18712
On Tue, Jan 10, 2012 at 10:32 AM, Nick Dokos <nicholas.dokos@hp.com> wrote:
> Chris Angelico <rosuav@gmail.com> wrote:
>> Point to note: The inverse operation, getting IP addresses from names,
>
> so socket.gethostbyaddr(os.environ['REMOTE_ADDR'])[0] is the 0th element
> of the tuple, i.e. the *name* that is returned.

Correct, I was drawing a noteworthy parallel with the inverse - gethostbyname.

ChrisA

[toc] | [prev] | [next] | [standalone]


#18346

FromΝικόλαος Κούρας <nikos.kouras@gmail.com>
Date2012-01-02 11:54 -0800
Message-ID<9d7740a3-90e2-44bf-ab46-9d98f3c5518c@x20g2000yqe.googlegroups.com>
In reply to#18339
On 2 Ιαν, 20:42, Roy Smith <r...@panix.com> wrote:
> In article
> <bacea15d-fae0-4b1f-8a8e-a8b06b561...@t30g2000vbx.googlegroups.com>,
>  ÉΪɫɻόλαος Κούρας <nikos.kou...@gmail.com> wrote:
>
> > I'am trying to present myself through my webpage as computer tech.
> > Is the background music so bad?! :-)
>
> Yes.  Background music on web sites is evil.

Evil?!?! How come? :)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web