finding the position sys.argv() arguments

  arguments, passwords, position, python, sys

Finding the position sys.argv() arguments


Hey there

I’m trying to add command line arguments to my python script using the sys.argv() function, I have got the basics down, but I’m really doing y head in trying to figure out how some of the things work. First of all, what I’m building is a password cracking / hashing tool. And secondly, my main current problem right now is looking for the position of arguments.

'''
_____________________________________________________________
        |
  -dict   / -d  |  Initiate a dictionary attack on an any kind of hash
  -hash   / -H  |  Hashes a password into an any kind of hash
        |
  All hashtypes supported:
  MD5, SHA1, SHA224, SHA384, SHA256, SHA512
-------------------------------------------------------------
'''
-hT = hashType

For example: python3 main.py -d -hT md5

What I want to do is find the position of where, -hT or any other arguments are and I can get the position as a value. Currently the method I was trying… which by the way is so scuffed, it got to the point of where it was legit causing scoping issues.

if '-pH' in args:
        if '-ph' in args[2]:
            password_hi = args[3]
            print(password_hi)
        elif '-ph' in args[4]:
            password_hi = args[5] 
...

Turns out, that isn’t a very efficient way of doing things. But anyway, if someone can explain how i get the argument position from a specific argument (string e.g. "-pH"), I would greately appreciate i. 🙂

Source: Python Questions

LEAVE A COMMENT