Results 1 to 6 of 6

Thread: simple python question

  1. #1
    Just burned his ISO
    Join Date
    Mar 2010
    Posts
    24

    Question simple python question

    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

  2. #2
    Very good friend of the forum Gitsnik's Avatar
    Join Date
    Jan 2010
    Location
    The Crystal Wind
    Posts
    851

    Default

    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.

  3. #3
    Just burned his ISO
    Join Date
    Mar 2010
    Posts
    24

    Default

    yeah posted similar post over on reddit - got the reply

    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.
    and as Gitsnik stated a quick google search for:

    "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

  4. #4
    Super Moderator Archangel-Amael's Avatar
    Join Date
    Jan 2010
    Location
    Somewhere
    Posts
    8,012

    Default

    Quote Originally Posted by The Fool View Post
    finds pretty much anything you need, i especially found the dive into python to be helpful,
    Dive Into Python
    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.

  5. #5
    Junior Member Sniffing4Prison's Avatar
    Join Date
    May 2009
    Posts
    26

    Default

    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
    
    ###### ######

  6. #6
    Senior Member shamanvirtuel's Avatar
    Join Date
    Mar 2010
    Location
    Somewhere in the "Ex" human right country
    Posts
    2,988

    Default powerfull and simplier

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •