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


Groups > comp.lang.python > #28970

Re: using text file to get ip address from hostname

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'output': 0.04; 'subject:text': 0.05; 'subject:file': 0.07; 'python': 0.09; 'already.': 0.09; 'hostname': 0.09; 'iterate': 0.09; 'received :mail-vc0-f174.google.com': 0.09; 'sep': 0.09; 'subject:using': 0.09; 'file,': 0.15; "(you're": 0.16; '2.7.3': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable:': 0.16; 'looping': 0.16; 'screen,': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'issue.': 0.20; 'file.': 0.20; 'file:': 0.22; "haven't": 0.23; 'header:In-Reply-To:1': 0.25; 'expand': 0.26; 'am,': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'all.': 0.28; 'pointer.': 0.29; 'received:209.85.220.174': 0.29; "i'm": 0.29; 'basic': 0.30; 'url:python': 0.32; 'file': 0.32; 'could': 0.32; 'docs': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'open': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'url:org': 0.36; 'url:library': 0.36; "i'll": 0.36; 'address.': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'address': 0.60; 'most': 0.61; 'worth': 0.63; 'else.': 0.65; 'want,': 0.65; 'enjoy': 0.67; 'fact,': 0.69; 'subject:get': 0.81; 'addresses;': 0.84; 'done:': 0.84; 'presumably': 0.84; 'reading,': 0.84; 'url:functions': 0.84; 'url:reference': 0.84; 'you;': 0.84; 'url:tutorial': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=tLqgYAZzlqcdiXYiYWIvujLTJi28ML3Z7HvxzQ0iGEs=; b=P3x5Nnxlywx9w6jtOhUzEjXHu4287VSjiKMskM1kUcLLEyX/gfud+BOyJ41qRVa04W wd/JmQOyLR5toRs/3QoxiwVaMWF5tYQYJCBKS7zpD2O5Gb8+fwoNg834vW0/DjzzXyX5 TZQc4BM6Vy0nViznMTpOwk5MHQDPP7WXXhBXvDgWImf8UDJ4NHjqi/q01eGdW/hydqlA /MeZhT5ZkHuLpT2IdY0hJGFRhvGvpQyOxquCRmvHzz8oIEm7bUAyDwNOLGtn2oBcQamu vKDj/V5E0WbhoMBpFYtpYgTSby6ER0OclhwX3/9rjDTV6fICvl8SRYbbHiEqaQGnMBRL zZzA==
MIME-Version 1.0
In-Reply-To <e4e100d1-bdf9-45d0-a137-615b1e820cfb@googlegroups.com>
References <e4e100d1-bdf9-45d0-a137-615b1e820cfb@googlegroups.com>
Date Thu, 13 Sep 2012 00:35:30 +1000
Subject Re: using text file to get ip address from hostname
From Chris Angelico <rosuav@gmail.com>
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.565.1347460533.27098.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347460533 news.xs4all.nl 6954 [2001:888:2000:d::a6]:34724
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28970

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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