From d442af0299653a466289e3ef0c9d4978f2988a35 Mon Sep 17 00:00:00 2001 From: codeshadow Date: Thu, 21 Dec 2017 22:00:21 -0400 Subject: [PATCH] Adding proxychains output format --- proxybroker/cli.py | 9 ++++++++- proxybroker/proxy.py | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/proxybroker/cli.py b/proxybroker/cli.py index 2d29d57..768c404 100644 --- a/proxybroker/cli.py +++ b/proxybroker/cli.py @@ -264,7 +264,7 @@ def add_format_arg(group): nargs='?', type=str.lower, help='''Flag indicating in what format the results will be presented. - Available formats: default and json''') + Available formats: default, proxychains and json''') def add_show_stats_arg(group): @@ -297,6 +297,7 @@ def outformat(outfile, format): async def handle(proxies, outfile, format): with outformat(outfile, format): is_json = format == 'json' + is_proxychains = format == 'proxychains' is_first = True while True: proxy = await proxies.get() @@ -305,6 +306,8 @@ async def handle(proxies, outfile, format): if is_json: line = '%s' % json.dumps(proxy.as_json()) + if is_proxychains: + line = '%s\n' % proxy.as_proxychains() else: line = '%r\n' % proxy @@ -373,3 +376,7 @@ def cli(args=sys.argv[1:]): finally: loop.stop() loop.close() + + +if __name__ == "__main__": + cli() diff --git a/proxybroker/proxy.py b/proxybroker/proxy.py index 8c3666f..12c6302 100644 --- a/proxybroker/proxy.py +++ b/proxybroker/proxy.py @@ -114,6 +114,10 @@ def types(self): """ return self._types + def as_proxychains(self): + tp = list(self.types.keys())[0] if self.types.keys() else "http" + return "%s %s %s" % (tp.lower(), self.host, self.port) + @property def is_working(self): """True if the proxy is working, False otherwise.