Python is not my thing, so I won't answer straight out, but the term you are looking for is "command line argument". Usually pertaining to the argv variable.
Make sure you post back after you've googled so that others can learn, yes?
hello everyone, I wrote a very simple python script to pipe into aircrack-ng. My question is how can i enter a variable on commencement?
or how can i make this work:
$ python3 script.py -p /usr/file/document.txt
so that the script can use the path i've entered.
I looked around a bit with google already but i could think of how to pose my question without this whole explanation.
-thanks much
Python is not my thing, so I won't answer straight out, but the term you are looking for is "command line argument". Usually pertaining to the argv variable.
Make sure you post back after you've googled so that others can learn, yes?
Still not underestimating the power...
There is no such thing as bad information - There is truth in the data, so you sift it all, even the crap stuff.
yeah posted similar post over on reddit - got the reply
and as Gitsnik stated a quick google search for:sys.argv contains the arguments entered at the command line. You can also use a program like getopt that does most of the work for you.
"python command line arguments"
finds pretty much anything you need, i especially found the dive into python to be helpful, i can't post the link yet but for me at least it was the first one and was titled "5.12. Handling command line arguments" i'm sure searching that will get you there
To be successful here you should read all of the following.
ForumRules
ForumFAQ
If you are new to Back|Track
Back|Track Wiki
Failure to do so will probably get your threads deleted or worse.
arg values are stored in sys.argv
Code:###### script.py ###### import sys, curdir flag = ([]) flat_t = ( "" ) for arg in sys.argv: if (flag_t == true): flag.append(arg) break if "-p" in arg: flag_t = true if "|" in arg: print "Something went wrong. No flags found." break if flag_t == "": print "there were no flags." sys.exit() try: my_awesome_text = open(str(os.curdir) + str(flag.pop()), 'r') except: print "didn't open that awesome text." sys.exit() INPUT = my_awesome_text.readlines() for password in INPUT: work your magic here ###### ######
import sys,optparse
parser = optparse.OptionParser(version="%prog 1.0")
parser.add_option('-p', action="store",dest="file",help="Document to parse")
if len(sys.argv)<2:
parser.print_help()
sys.exit(0)
(options, args)=parser.parse_args()
print "\nFILENAME is "+options.file
RESULTS:
test.py : will print autogenerated help
test.py -h or --help : will print autogenerated help
test.py --version : will print version string
test.py -p pathtotextfile : will print the filename (do what you want ....)
it also handle auto the lack of argument on an option
it also handle auto bad options ...
hope it helps
Watch your back, your packetz will belong to me soon... xD
BackTrack : Giving Machine Guns to Monkeys since 2006