Quick question on stripping, I'm executing a simple program, but whenever I try and run it in Terminal, it strips all wrong. The error it puts out is below. It iterates [+]Trying: admin/admin for the first line, but wont repeat it for the rest of the lines, as well as messing up right around pass/passg:, stripping the wrong thing, (It's supposed to say 'pass/pass'.

Any ideas?

+] Trying: admin/admin
Traceback (most recent call last):
  File "/Users/someuser/Desktop/Python3/logon.py", line 27, in <module>
    iterate(host, passwdFile) 
  File "/Users/someuser/Desktop/Python3/logon.py", line 10, in logon
    passWord = line.split(':')[1].strip('\n').strip('\r') 
IndexError: list index out of range

def iterate(hostname, passwdFile):
    pF = open(passwdFile, 'r') 
    for line in pF.readlines():
        userName = line.split(':')[0] 
        passWord = line.split(':')[1].strip('\n').strip('\r') 
        print '[+] Trying: ' + userName + "/" + passWord

passwdFile = 'some password file, formatted like [user:password], then a newline, [user:password]...'

IndexError: list index out of range

>>> l = [1,2]
>>> l[1]
>>> l[2]
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
IndexError: list index out of range

A simple print should tell you what is wrong print passWord.

If it split at at :,you will be able to call index 1 as shown in this example.
If not you get a IndexError.

>>> s = 'hello:world\n\r'
>>> s.split(':')
['hello', 'world\n\r']
>>> s.split(':')[1].strip()

Edited 3 Years Ago by snippsat

This question has already been answered. Start a new discussion instead.