title: extracting IP address from text file and use them as input in Python
body: <p>I am currently trying to get ip address from text. But the code I tried is only getting the last line from the file. I am using the following code</p>
  
  <pre><code>import paramiko
  import time
  import getpass
  import sys
  import socket
  import re
  
  user = raw_input("Enter you username: ")
  password = getpass.getpass()
  inp = open(r'ipaddressrouter.txt', 'r') 
  
  
  for line in inp:
      try:
          ssh_client = paramiko.SSHClient()
          ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
          ssh_client.connect(hostname=line,username=user,password=password)
          print "Successful Connection to " + line + '\n'
          stdin, stdout, stderr = ssh_client.exec_command('sh ip int b \n')
          output = stdout.read()
          out = open('out.txt', 'a')
          out.write(line + '\n')  
          out.write(output + '\n')
          out.write('\n')
      except (socket.error, paramiko.AuthenticationException):
              status = 'fail' 
  
  ssh_client.close
  </code></pre>
  
  <p>help would be appreciated</p>
  
  <p>Update:</p>
  
  <p>When I removed except</p>
  
  <p>I got the following error</p>
  
  <p>File "C:\Users\abc\Desktop\Python Test Scripts\newstest2.py", line 20, in
   </p>
  
  <p>ssh_client.connect(hostname=host,username=user,password=password)</p>
  
  <p>File "C:\Python27\lib\site-packages\paramiko\client.py", line 329, in connect to_try = list(self._families_and_addresses(hostname, port))
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 200, in _families_and_addresses hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM)socket.gaierror: [Errno 11004] getaddrinfo failed</p>
  
  <p>Can some one help me out ?</p>