Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29012
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <jsf80238@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python3': 0.05; 'socket': 0.05; 'subject:text': 0.05; 'subject:file': 0.07; 'python': 0.09; 'addr': 0.09; 'hostname': 0.09; 'subject:using': 0.09; "'is',": 0.16; '{0}': 0.16; 'skip:{ 20': 0.17; '>>>': 0.18; 'sender:addr:gmail.com': 0.18; 'import': 0.21; 'received:209.85.214.174': 0.21; 'header:In-Reply-To:1': 0.25; 'skip:# 10': 0.27; 'message-id:@mail.gmail.com': 0.27; 'cat': 0.29; 'print': 0.32; 'skip:s 30': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'list': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'address': 0.60; 'skip:6 10': 0.63; 'more': 0.63; 'subject:get': 0.81 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=g/kBzlZQbx2cS2JYl765d8xI9LeHSBoQrC2irfPcW6k=; b=naHSGs5y8GtLGDiarONwFrv2y1fxfXWfvY1slzTY4U7iiXFr/hi7jEAdMWH/IRAHfe C/99C9JZb0iSpvlS0hGwQFs3qz53DMMkHMBgSLcEVV7Kf3+5+GFt2XF9QNRvNRET+abE brl4HZFHlA+4o+MDkAnOv9XjskKo3vyj+McdKgiM7+MwGfuVb1Y+t+a8E6C7tVDFazG9 Mw00vXzztTmLF6H2qkaHxplxGL2LWhOIDQfWcIgWHILC2Ph4wKqmpiDgW/IoKohbrqwv XjYIHQldb1E++sASk73zbAqu080Rk9rLNx5CE9Rz99+ZZ0aqBvQLd0qk08Ot/vxwY5jc G2zQ== |
| MIME-Version | 1.0 |
| Sender | jsf80238@gmail.com |
| In-Reply-To | <e4e100d1-bdf9-45d0-a137-615b1e820cfb@googlegroups.com> |
| References | <e4e100d1-bdf9-45d0-a137-615b1e820cfb@googlegroups.com> |
| Date | Wed, 12 Sep 2012 21:12:52 -0600 |
| X-Google-Sender-Auth | 0BQ7otjdRTqRt2-HyfjVoyWVqUU |
| Subject | Re: using text file to get ip address from hostname |
| From | Jason Friedman <jason@powerpull.net> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.591.1347505975.27098.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1347505975 news.xs4all.nl 6953 [2001:888:2000:d::a6]:34816 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:29012 |
Show key headers only | View raw
> i need to get an ip address from list of hostnames which are in a textfile.
>
> this is what i have so far
> --------------------------------------------------------------------------
> #!/usr/bin/env python
> #Get the IP Address
>
> import socket
> hostname = 'need it to read from a text file'
> addr = socket.gethostbyname(hostname)
> print 'The address of ', hostname, 'is', addr
$ cat hostnames
google.com
microsoft.com
facebook.com
$ python3
Python 3.2.3 (default, May 3 2012, 15:51:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> for line in open("hostnames"):
... hostname = line.strip()
... print("IP address for {0} is {1}.".format(hostname,
socket.gethostbyname(hostname)))
...
IP address for google.com is 74.125.225.33.
IP address for microsoft.com is 64.4.11.37.
IP address for facebook.com is 69.171.237.16.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
using text file to get ip address from hostname dkatorza@gmail.com - 2012-09-12 07:24 -0700
Re: using text file to get ip address from hostname Chris Angelico <rosuav@gmail.com> - 2012-09-13 00:35 +1000
Re: using text file to get ip address from hostname dkatorza@gmail.com - 2012-09-12 07:41 -0700
Re: using text file to get ip address from hostname Alister <alister.ware@ntlworld.com> - 2012-09-12 17:51 +0000
Re: using text file to get ip address from hostname Terry Reedy <tjreedy@udel.edu> - 2012-09-12 17:04 -0400
Re: using text file to get ip address from hostname Jason Friedman <jason@powerpull.net> - 2012-09-12 21:12 -0600
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-15 09:20 -0700
Re: using text file to get ip address from hostname Hans Mulder <hansmu@xs4all.nl> - 2012-09-15 20:52 +0200
Re: using text file to get ip address from hostname Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-17 22:37 +0200
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-15 15:43 -0700
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 00:41 -0700
Re: using text file to get ip address from hostname Chris Angelico <rosuav@gmail.com> - 2012-09-19 18:14 +1000
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 01:50 -0700
Re: using text file to get ip address from hostname Chris Angelico <rosuav@gmail.com> - 2012-09-19 18:59 +1000
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 01:50 -0700
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 02:10 -0700
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 02:10 -0700
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 05:28 -0700
Re: using text file to get ip address from hostname Dave Angel <d@davea.name> - 2012-09-19 14:22 -0400
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 05:28 -0700
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 22:13 -0700
Re: using text file to get ip address from hostname Dan Katorza <dkatorza@gmail.com> - 2012-09-19 22:13 -0700
csiph-web