[英]Error handling with verbose output
Im trying to implement the --verbose
option in my script. 我试图在脚本中实现--verbose
选项。 The idea is to turn on extra printing of errors etc for debugging, but for some reason it doesnt seem to work. 这个想法是打开额外的错误等打印信息以进行调试,但是由于某种原因,它似乎不起作用。 Ive tried a few variations of the if verbose
statement but no joy. Ive尝试了if verbose
语句的几种变体,但没有喜悦。 Im hoping someone could point me in the right direction? 我希望有人能指出我正确的方向吗?
CLI EXAMPLE CLI示例
./attack2.py -f wordfile.txt -d google.com --verbose 1
CLI OUTPUT CLI输出
unknown@ubuntu:~$ ./attack2.py -f wordfile.txt -d google.com --verbose 1
173.194.34.149
173.194.34.130
unknown@ubuntu:~$
ARG PRINT ARG PRINT
{'--domain': 'google.com',
'--file': 'wordfile.txt',
'--help': False,
'--thread': False,
'--verbose': True,
'10': False,
'<1>': '1'}
CODE 码
#!/usr/bin/python
"""
Description:
Basic Domain bruteforcer
Usage:
attack2.py (-f <file>) (-d <domain>) [-t 10] [-v <1>]
attack2.py -h | --help
Arguments:
-f --file File to read potential Sub-domains from. (Required)
-d --domain Domain to bruteforce. (Required)
Options:
-h --help Show this screen.
-p --proxy Proxy address and port. [default: http://127.0.0.1:8080] (Optional)
-t --thread Thread count. (Optional)
-v --verbose Turn debug on. (Optional)
"""
import socket
from docopt import docopt
def fread(dwords):
flist = open(dwords).readlines()
return [s.replace('\n', '.') for s in flist]
def subcheck(subdomain, domain, verbose):
vdomain = {}
for sub in subdomain:
try:
check = socket.gethostbyname(sub + domain)
vdomain[sub + domain] = check
except socket.gaierror, e:
if verbose == True:
print arguments
print e, sub + domain
else:
pass
return vdomain
if __name__ == "__main__":
arguments = docopt(__doc__, version='0.1a')
fread(arguments['--file'])
returned_list = fread(arguments['--file'])
returned_domains = subcheck(returned_list, arguments['--domain'], ['--verbose'])
The below line in function subcheck
功能子subcheck
的以下行
returned_domains = subcheck(returned_list, arguments['--domain'], ['--verbose'])
should be 应该
returned_domains = subcheck(returned_list, arguments['--domain'], arguments['--verbose'])
You forgot to pass the verbose
param from arguments, instead you passed a list
您忘记了传递参数的verbose
参数,而是传递了一个list
It seems I was calling the subcheck incorrectly. 看来我叫错了子检查。
Code should have looked like this 代码应该看起来像这样
Working CODE 工作代码
if __name__ == "__main__":
arguments = docopt(__doc__, version='0.1a')
fread(arguments['--file'])
returned_list = fread(arguments['--file'])
returned_domains = subcheck(returned_list, arguments['--domain'], arguments['--verbose'])
print returned_domains
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.