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


Groups > comp.lang.python > #3992

Re: sockets: bind to external interface

From Jean-Paul Calderone <calderone.jeanpaul@gmail.com>
Newsgroups comp.lang.python
Subject Re: sockets: bind to external interface
Date 2011-04-25 13:13 -0700
Organization http://groups.google.com
Message-ID <8ebb3b18-b983-4ff6-97eb-c062813d11c7@d12g2000vbz.googlegroups.com> (permalink)
References <k4vg88-0tt.ln1@svn.schaathun.net> <mailman.815.1303760950.9059.python-list@python.org>

Show all headers | View raw


On Apr 25, 3:49 pm, Chris Angelico <ros...@gmail.com> wrote:
> On Tue, Apr 26, 2011 at 5:37 AM, Hans Georg Schaathun <h...@schaathun.net> wrote:
>
> > Has anyone found a simple solution that can be administered without
> > root privileges?  I mean simpler than passing the ip address
> > manually :-)
>
> You can run 'ifconfig' without being root, so there must be a way. At
> very worst, parse ifconfig's output.
>
> The way you talk of "the" external interface, I'm assuming this
> computer has only one. Is there a reason for not simply binding to
> INADDR_ANY aka 0.0.0.0? Do you specifically need to *not* bind to
> 127.0.0.1?
>
> Chris Angelico

Binding to 0.0.0.0 is usually the right thing to do.  The OP should
probably do that unless he has some particular reason for doing
otherwise.  The comment about "the standard solution of binding to
whatever socket.gethostname() returns" suggests that perhaps he wasn't
aware that actually the standard solution is to bind to 0.0.0.0.

However, the system stack can usually be tricked into revealing some
more information this way:

    >>> import socket
    >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    >>> s.connect(('1.2.3.4', 1234))
    >>> s.getsockname()
    ('192.168.1.148', 47679)

Jean-Paul

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

sockets: bind to external interface Hans Georg Schaathun <hg@schaathun.net> - 2011-04-25 20:37 +0100
  Re: sockets: bind to external interface Chris Angelico <rosuav@gmail.com> - 2011-04-26 05:49 +1000
    Re: sockets: bind to external interface Jean-Paul Calderone <calderone.jeanpaul@gmail.com> - 2011-04-25 13:13 -0700
    Re: sockets: bind to external interface Hans Georg Schaathun <hg@schaathun.net> - 2011-04-25 21:14 +0100
      Re: sockets: bind to external interface Hans Georg Schaathun <hg@schaathun.net> - 2011-04-25 21:24 +0100
        Re: sockets: bind to external interface Chris Angelico <rosuav@gmail.com> - 2011-04-26 07:21 +1000
      Re: sockets: bind to external interface Chris Angelico <rosuav@gmail.com> - 2011-04-26 06:30 +1000
        Re: sockets: bind to external interface Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-25 23:18 +0200
          Re: sockets: bind to external interface Chris Angelico <rosuav@gmail.com> - 2011-04-26 07:50 +1000
          Re: sockets: bind to external interface Hans Georg Schaathun <hg@schaathun.net> - 2011-04-26 06:20 +0100
      Re: sockets: bind to external interface Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-25 23:14 +0200
  Re: sockets: bind to external interface Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-04-26 11:24 +0200

csiph-web