Вопрос

I'm creating my first python tool, if you want to call it that. (I work in IT Security, btw)

It was going well until I tried to call a function from the main function. I'm sure it's something simple that I'm missing :(. Could someone point me in the right direction? Then feel free to point and laugh.

#!/usr/bin/python

import sys, getopt, socket

def usage():
    print "-h --help: help\n"
    print "-f --file: File to read bruteforce domain list from.\n"
    print "-p --proxy: Proxy address and port. e.g http://192.168.1.64:8080\n"
    print "-d --domain: Domain to bruteforce.\n"
    print "-e: Turn debug on.\n"
    sys.exit()

def main(argv):
    file = None
    proxy = None
    domain = None
    try:
       opts, argv =getopt.getopt(argv, "h:f:p:d:e",["help", "file=", "proxy=", "domain="])

     except getopt.GetoptError as err:
       print str(err)
       usage()
       sys.exit(2)

     for opt, arg in opts:
       if opt in ("-h", "--help"):
       usage()
       sys.exit()
     elif opt in ("-f", "--file"):
       file = arg
     elif opt in ("-p", "--proxy"):
       proxy = arg
     elif opt in ("-d", "--domain"):
       domain = arg
     elif opt in '-e':
       global _debug
       _debug = 1
     else:
        assert Flase, "Unhandled option"
print fread.flist

def fread(file, *args):
   flist = open(file).readlines()
   return


if __name__ == "__main__":
  main(sys.argv[1:])
Это было полезно?

Решение

The issue is with your statement print fread.flist. You can't access variables assigned inside functions this way. Instead, change your fread() function to the following:

def fread(file, *args):
   flist = open(file).readlines()
   return flist

and change the statement above to

print fread(file)

where file is the file you want to access.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top