用了三天左右时间重构了 ‘webdog’,简单的整理后开源了 -> WebHunt。
命令行的设计
首先是对命令行的设计,之前没有注意到这些细节,导致命令行的程序很难用,网上可以搜索一些”命令行的设计“文章或者项目看看。
命令行处理使用 click
模块,将其分为了 manage
和 scan
两个组:
具体如下:
manage:
Options:
-d, --directory TEXT Components directory, default ./components
-l, --list List components
--pull Pull custom components from remote database
--pull_webanalyzer Pull custom components from remote database
--sync Synchronize to remote database
--sync-updating Update existing components when synchronizing to
remote database
--host TEXT MySQL database host
--port INTEGER MySQL database port
--db TEXT MySQL database name
--user TEXT MySQL database user
--passwd TEXT MySQL database password
--search TEXT Search component name
-v, --verbose Output detailed debugging information
--help Show this message and exit.
scan:
Options:
-u, --url TEXT Target [required]
-d, --directory TEXT Components directory, default ./components
-a, --aggression Open aggression mode
-U, --user-agent TEXT Custom user agent
-H, --header TEXT Pass custom header LINE to serve
--disallow-redirect Disallow redirect
-c, --component TEXT Specify component
-t, --max-threads INTEGER Set the maximum number of threads
--proxy TEXT Set proxy is like: '[HTTP/SOCKS4/SOCKS5]/[usernam
e]@[password]/[addr]:[port]'
--proxy_rdns Proxy uses rdns
-v, --verbose Output detailed debugging information
--help Show this message and exit.
简单解决命令交互终端下的彩色输出
这样就不用安装第三方模块
|
|
尽可能的 Pythonic
- 类方法的使用
|
|
|
|
- 属性缓存装饰器
属性缓存,获取该属性时将该方法执行结果写入 obj.__dict__
中
|
|
- 线程安全的属性装饰器
|
|
- 使用 Mixin 类
例如 RequestManagerMixin 是个具有自己历史的线程安全请求管理器…
|
|
感觉代码质量比之前的项目好了不少 🤔。