How to get IP address

Jp Calderone exarkun at intarweb.us
Sun Mar 2 13:22:12 EST 2003


On Sun, Mar 02, 2003 at 03:06:06PM +0100, Nagy L?szl? Zsolt wrote:
> [snip]
> Sorry, but this does not help me. I want to determine the IP address
> because I want to send my external IP address to a dynamic DNS provider
> (in an A record). I get my IP address with DHCP and I'm writting a program
> that assigns a DNS name to a given IP address. So my hostname may have a
> bad IP address assigned at the time when I need the IP address. IP address
> is a lower level than DNS name. I can have an IP address without hostname.
> Can you tell me a solution in the case when I have no valid DNS name?
> Thanks.


  There's a hackish solution that somewhat works -

    import socket
    s = socket.socket()
    s.connect(('arbitrary.host', arbitraryPort))
    dottedQuad = s.getsockname()[0]


  I recommend using something like your ISPs news or email server for the
arbitrary host and port, since these will usually be fast to connect to.

  Jp

-- 
 up 21 days, 22:29, 6 users, load average: 0.25, 0.46, 0.44
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030302/76af14d0/attachment.sig>


More information about the Python-list mailing list