From a55c42e0f1f72a64196d006d1e5e8b5214b8632c Mon Sep 17 00:00:00 2001 From: R4SAS Date: Tue, 30 Apr 2019 07:30:46 +0300 Subject: [PATCH] proxy checker --- .gitignore | 2 ++ README.md | 41 +++++++++++++++++++++++ bin/checker.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ check | 9 ++++++ check.bat | 32 ++++++++++++++++++ list.example.ini | 34 ++++++++++++++++++++ 6 files changed, 202 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 bin/checker.py create mode 100755 check create mode 100644 check.bat create mode 100644 list.example.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..90f867d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/list.ini +/result.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b41bed --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +Proxy checker +===== + +Written on python, requires at least version 3.4. + +For work needed PySocks and urllib3, install it with pip: +``` +$ python3 -m pip install PySocks +$ python3 -m pip install urllib3 +``` + +That script written primary for checking I2P proxy tunnels. + +Configuring +----- + +Fill `list.ini` with your tunnels options as in example file. + +At same time you need that tunnels configured in your tunnels.conf (i2pd) or tunnels page (i2p). + +Example for *false.i2p* outproxy usage in i2pd: +``` +[FALSE] +type = httpproxy +address = 127.0.0.1 +port = 4450 +outproxy = http://77mpz4z6s4eenjexleclqb36uxvqjtztqikjfqa4sovojh6gwwha.b32.i2p +keys = false.dat +``` + +And, according to that tunnel, proxy checker config: +``` +[4450] +type = http +address = 77mpz4z6s4eenjexleclqb36uxvqjtztqikjfqa4sovojh6gwwha.b32.i2p +name = false.i2p +owner = meeh +info = httpproxy +``` + +**Note that fields PORT and TYPE is required!** Other fields is not required and used only for filling table output. diff --git a/bin/checker.py b/bin/checker.py new file mode 100755 index 0000000..d4581da --- /dev/null +++ b/bin/checker.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 + +import sys, configparser +from datetime import datetime +import socket, urllib.request +## PySocks +import socks +from sockshandler import SocksiPyHandler + +TESTURI = "https://google.com/" +PROXYHOST = "127.0.0.1" +TIMEOUT = 30 + +## https://stackoverflow.com/a/14906787 +class Logger(object): + def __init__(self): + self.terminal = sys.stdout + self.log = open("result.txt", "w") + + def write(self, message): + self.terminal.write(message) + self.log.write(message) + + def flush(self): + self.terminal.flush() + +sys.stdout = Logger() + +def checkproxy(port, type): + if type == 'http': + handler = socks.HTTP + elif type == 'socks': + handler = socks.SOCKS5 + elif type == 'http0': + proxy = urllib.request.ProxyHandler({'http': PROXYHOST +':' + str(port)}) + else: + print("[unsupported type]") + return + + if type == 'http0': + opener = urllib.request.build_opener(proxy) + else: + opener = urllib.request.build_opener( + SocksiPyHandler(handler, PROXYHOST, port) + ) + + try: + response = opener.open(TESTURI, timeout=TIMEOUT).read() + except Exception as e: + print("[%5s]" % ('dead')) + return + + print("[%5s]" % ('alive')) + +def main(): + # Read list with ports and information + config = configparser.ConfigParser() + config.read('list.ini') + proxyList = config.sections() + + print("Started check at %s UTC" % (datetime.utcnow())) + print("Types: HTTP - using SocksiPyHandler, HTTP0 - using urllib, SOCKS - only 5th version using SocksiPyHandler") + print("[%5s] [%5s] [%60s] [%16s] [%16s] [%16s] [%5s]" % + ('PORT','TYPE','B32 ADDRESS','NAME','OWNER','INFO','STATUS')) + + for currentProxy in proxyList: + tunnel = dict(config.items(str(currentProxy))) + + print( + "[%5d] [%5s] [%60s] [%16s] [%16s] [%16s] " % ( + int(currentProxy), + tunnel['type'] if ("type" in tunnel) else "none", + tunnel['address'] if ("address" in tunnel) else "", + tunnel['name'] if ("name" in tunnel) else "", + tunnel['owner'] if ("owner" in tunnel) else "", + tunnel['info'] if ("info" in tunnel) else "" + ), + end='', flush=True + ) + + checkproxy(int(currentProxy), str(config[currentProxy]['type'])) + +if __name__ == '__main__': + main() diff --git a/check b/check new file mode 100755 index 0000000..2ca7fe3 --- /dev/null +++ b/check @@ -0,0 +1,9 @@ +#!/bin/sh + +findpy3=$(which python3) +if [ -z $findpy3 ]; then + echo "Can't find 'pyhton3' installed. That script needs it!"; + exit 1; +fi + +$findpy3 bin/checker.py \ No newline at end of file diff --git a/check.bat b/check.bat new file mode 100644 index 0000000..0a16851 --- /dev/null +++ b/check.bat @@ -0,0 +1,32 @@ +@echo off +title Checking tunnels... +SET PY_PYTHON=3 + +for %%X in (python3.exe) do (set FOUND=%%~$PATH:X) +if defined FOUND ( + set xPy=%FOUND% + goto RUN_CHECK +) + +for %%X in (python.exe) do (set FOUND=%%~$PATH:X) +if defined FOUND ( + %FOUND% -c "import sys; print(sys.version_info[0])" | find "3" >nul && set xyes=1 || set xyes=0 + if "%xyes%" == 1 ( + set xPy=%FOUND% + goto RUN_CHECK + ) else ( + echo Error: Python3 not found! + pause + exit + ) +) else ( + echo Error: Python3 not found! + pause + exit +) + +:RUN_CHECK +%xPy% bin\checker.py + +echo Done... +pause > nul \ No newline at end of file diff --git a/list.example.ini b/list.example.ini new file mode 100644 index 0000000..0807e60 --- /dev/null +++ b/list.example.ini @@ -0,0 +1,34 @@ +; REQIRED FIELDS IS PORT and TYPE! +; Other fields is not required +; +; Указание полей PORT и TYPE обязательно! +; Остальные можно заполнять чем угодно, +; они используются только для вывода информации в таблицу +; +; [PORT] +; type = type of proxy (http - using SocksiPyHandler, http0 - using urllib, socks - only 5th version using SocksiPyHandler) +; address = base32 address +; name = name of tunnel +; owner = name of owner +; info = some info + +[4450] +type = http +address = 77mpz4z6s4eenjexleclqb36uxvqjtztqikjfqa4sovojh6gwwha.b32.i2p +name = false.i2p +owner = meeh +info = httpproxy + +[4465] +type = socks +address = hob3qpw7c6yaurusuzlden66tp4opksrqqukywefnqyj6lhauhoa.b32.i2p +name = public +owner = r4sas +info = client + +[4470] +type = http +address = wfigbdfs6tvajiw24xwohbwwy5pq3jcgzevwnsky2ucwzwgodumq.b32.i2p +name = blue +owner = arctic +info = httpproxy