title: Python program exiting after a success in a try: block
body: <p>So I'm making a python program that would ping a host and see if that host has the port open. But after the first host is discovered, the program exits. I want the program to write all the hosts that have port 22 open to the alive_hosts.txt file. Any help would be appreciated. Thanks!</p>
  <p>The hosts.txt file looks like this:</p>
  <p>192.168.1.1</p>
  <p>192.168.1.5</p>
  <p>192.168.2.13</p>
  <p>192.168.5.4</p>
  <p>...</p>
  <pre><code>import socket
  
  fp = open(&quot;hosts.txt&quot;, &quot;r&quot;)
  fp2 = open(&quot;alive_hosts.txt&quot;, &quot;a&quot;)
  
  Lines = fp.readlines()
  
  for line in Lines:
      try:
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          s.settimeout(0.37)
          result = s.connect_ex((line, 22))
          s.close()
          fp2.write(line + &quot;\n&quot;)
          continue
      except Exception:
          pass
          
  </code></pre>