Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89721
| X-Received | by 10.69.16.133 with SMTP id fw5mr14859461pbd.7.1430476904097; Fri, 01 May 2015 03:41:44 -0700 (PDT) |
|---|---|
| X-Received | by 10.140.95.109 with SMTP id h100mr101556qge.6.1430476903840; Fri, 01 May 2015 03:41:43 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!m20no7596495iga.0!news-out.google.com!a41ni924qgf.1!nntp.google.com!j5no4567318qga.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Fri, 1 May 2015 03:41:43 -0700 (PDT) |
| In-Reply-To | <mailman.6.1430475067.3347.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=2a02:f6e:a000:80:957:65b3:1c14:5a74; posting-account=l1AJTQoAAAAs0lut1s8mmXYv6pVnD-ku |
| NNTP-Posting-Host | 2a02:f6e:a000:80:957:65b3:1c14:5a74 |
| References | <f46cdd6e-5c94-4370-a368-cce0bd68c997@googlegroups.com> <mailman.6.1430475067.3347.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <c8a5569c-66aa-4b96-829e-36307d6947cb@googlegroups.com> (permalink) |
| Subject | Re: Am I missing something here? ipaddress vs socket |
| From | Ronald van Zantvoort <the.loeki@gmail.com> |
| Injection-Date | Fri, 01 May 2015 10:41:43 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:89721 |
Show key headers only | View raw
Hi Chris & Alain, thanks for responding :) On Friday, 1 May 2015 12:11:20 UTC+2, Chris Angelico wrote: > On Fri, May 1, 2015 at 7:42 PM, Ronald van Zantvoort wrote: > > Hi all, > > > > Given the following code: > > > > import ipaddress > > import socket > > > > ip = ipaddress.ip_address(mystring) > > sock_family = ip.???? > > socket = socket.socket(sock_family, socket.SOCK_STREAM) > > > > Am I crazy or is this undoable? > > > > sock.AF_INET == 2 > > sock.AF_INET6 == 10 > > ip.version == 4 or 6 > > Are you trying to look up a name to get an address? Or just look up an > address? The easiest way would be to use a ternary if: > > sock_family = sock.AF_INET if ip.version == 4 else sock.AF_INET6 mystring is already an IP address, sorry for not mentioning that. The point is that ternary if; I've been scouring around the internet and there's a million different variations on the same idea. I'm completely flabberghasted it's not a simple property within the object though, e.g. ip.sock_family. Was this a deliberate decision by the Python devs or can I try an RFE for that? > But you may find it convenient to use a dedicated function for > establishing a connection, which could look up an AAAA or A record for > a name, then proceed through all addresses, attempting connections in > turn. I'm fairly sure one exists in Python, but I can't right now > remember the name. > > ChrisA Well you've already got socket.create_connection(), which (I think) does perform that lookup.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Am I missing something here? ipaddress vs socket the.loeki@gmail.com - 2015-05-01 02:42 -0700
Re: Am I missing something here? ipaddress vs socket Chris Angelico <rosuav@gmail.com> - 2015-05-01 20:11 +1000
Re: Am I missing something here? ipaddress vs socket Ronald van Zantvoort <the.loeki@gmail.com> - 2015-05-01 03:41 -0700
Re: Am I missing something here? ipaddress vs socket Chris Angelico <rosuav@gmail.com> - 2015-05-01 22:06 +1000
Re: Am I missing something here? ipaddress vs socket Ronald van Zantvoort <the.loeki@gmail.com> - 2015-05-01 06:37 -0700
Re: Am I missing something here? ipaddress vs socket Chris Angelico <rosuav@gmail.com> - 2015-05-01 23:46 +1000
Re: Am I missing something here? ipaddress vs socket Ronald van Zantvoort <the.loeki@gmail.com> - 2015-05-01 06:48 -0700
Re: Am I missing something here? ipaddress vs socket Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2015-05-01 12:31 +0200
csiph-web