title: Read a list of hostnames and resolve to IP addresses
body: <p>i'm attempting to read a plain text file and resolve each IP address and (for now) just spit them back out on-screen. </p>
  
  <pre><code>import socket
  
  f = open("test.txt")
  num_line = sum(1 for line in f)
  f.close()
  
  with open("test.txt", "r") as ins:
          array = []
          for line in ins:
                  array.append(line)
  
  for i in range(0,num_line):
          x = array[i]
          print x 
          data = socket.gethostbyname_ex(x)
          print data
  </code></pre>
  
  <p>Currently I'm getting the following:</p>
  
  <pre><code>me@v:/home/# python resolve-list2.py
  test.com
  
  Traceback (most recent call last):
    File "resolve-list2.py", line 15, in &lt;module&gt;
      data = socket.gethostbyname_ex(x)
  socket.gaierror: [Errno -2] Name or service not known
  </code></pre>
  
  <p>Googling that error doesn't seem to help me... 
  The text file only contains one line at the moment (test.com) but i get the same error even with multiple lines/different hosts.</p>
  
  <p>Any suggestions? </p>
  
  <p>Thanks!</p>