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
guest/guest 
pass/passg: 
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
logout






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]...'

Recommended Answers

All 2 Replies

IndexError: list index out of range

>>> l = [1,2]
>>> l[1]
2
>>> 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()
'world'

Perfect! Thanks snippsat!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.