Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28970
| References | <e4e100d1-bdf9-45d0-a137-615b1e820cfb@googlegroups.com> |
|---|---|
| Date | 2012-09-13 00:35 +1000 |
| Subject | Re: using text file to get ip address from hostname |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.565.1347460533.27098.python-list@python.org> (permalink) |
On Thu, Sep 13, 2012 at 12:24 AM, <dkatorza@gmail.com> wrote: > i'm new to Python and i searched the web and could not find an answer for my issue. > > i need to get an ip address from list of hostnames which are in a textfile. This is sounding like homework, so I'll just give you a basic pointer. You have there something that successfully resolves one hostname to an IP address. Now you want to expand that to reading an entire file of them and resolving them all. Presumably you need to produce a list of IP addresses; check the question as to whether you need to create a file, or output to the screen, or something else. What you want, here, is to open a file and iterate over it. The most convenient way would be to have one hostname per line and iterate over the lines of the file. Check out these pages in the Python docs (you're using Python 2 so I'm going with Python 2.7.3 documentation): Opening a file: http://docs.python.org/library/functions.html#open Ensuring that it'll be closed when you're done: http://docs.python.org/reference/compound_stmts.html#the-with-statement Looping over an iterable: http://docs.python.org/tutorial/controlflow.html#for-statements See where that takes you; in fact, all of http://docs.python.org/tutorial/ is worth reading, if you haven't already. Have fun, enjoy Python! ChrisA
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