commit c70c068fa03e920ee0afdde9f0701ee28266a3e6 Author: luorijun Date: Mon Aug 18 15:48:15 2025 +0800 初始化仓库 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..460bd52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,206 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py.cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock +#poetry.toml + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. +# https://pdm-project.org/en/latest/usage/project/#working-with-version-control +#pdm.lock +#pdm.toml +.pdm-python +.pdm-build/ + +# pixi +# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. +#pixi.lock +# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one +# in the .venv directory. It is recommended not to include this directory in version control. +.pixi + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.envrc +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Abstra +# Abstra is an AI-powered process automation framework. +# Ignore directories containing user credentials, local state, and settings. +# Learn more at https://abstra.io/docs +.abstra/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the entire vscode folder +# .vscode/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Marimo +marimo/_static/ +marimo/_lsp/ +__marimo__/ + +# Streamlit +.streamlit/secrets.toml + +# 业务文件 +*.crt \ No newline at end of file diff --git a/config copy.csv b/config copy.csv new file mode 100644 index 0000000..28b1323 --- /dev/null +++ b/config copy.csv @@ -0,0 +1,221 @@ +index,name,code,gateway,public,mask,private +1,宣城,ahxc215,43.226.58.1,43.226.58.10,24,192.168.99.1 +2,宿州,ahsz216,43.226.58.1,43.226.58.11,24,192.168.99.2 +3,阜阳,ahfy225,43.226.58.1,43.226.58.12,24,192.168.99.3 +4,合肥,ahhf224,43.226.58.1,43.226.58.13,24,192.168.99.4 +5,淮南,ahhn222,43.226.58.1,43.226.58.14,24,192.168.99.5 +6,铜陵,ahtl218,43.226.58.1,43.226.58.15,24,192.168.99.6 +7,马鞍山,ahmas219,43.226.58.1,43.226.58.16,24,192.168.99.7 +8,黄山,ahhs221,43.226.58.1,43.226.58.17,24,192.168.99.8 +9,亳州,ahbz228,43.226.58.1,43.226.58.18,24,192.168.99.9 +10,安庆,ahaq230,43.226.58.1,43.226.58.19,24,192.168.99.10 +11,淮北,ahhb223,43.226.58.1,43.226.58.20,24,192.168.99.11 +12,滁州,ahcz226,43.226.58.1,43.226.58.21,24,192.168.99.12 +13,芜湖,ahwh217,43.226.58.1,43.226.58.22,24,192.168.99.13 +14,六安,ahla220,43.226.58.1,43.226.58.23,24,192.168.99.14 +15,蚌埠,ahbb229,43.226.58.1,43.226.58.24,24,192.168.99.15 +16,池州,ahchz227,43.226.58.1,43.226.58.25,24,192.168.99.16 +17,营口,lnlyk196,43.226.58.1,43.226.58.26,24,192.168.99.17 +18,鞍山,lnas204,43.226.58.1,43.226.58.27,24,192.168.99.18 +19,抚顺,lnfs201,43.226.58.1,43.226.58.28,24,192.168.99.19 +20,沈阳,lnsy198,43.226.58.1,43.226.58.29,24,192.168.99.20 +21,大连,lndl202,43.226.58.1,43.226.58.30,24,192.168.99.21 +22,朝阳,lncy203,43.226.58.1,43.226.58.31,24,192.168.99.22 +23,盘锦,lnpj199,43.226.58.1,43.226.58.32,24,192.168.99.23 +24,葫芦岛,lnhld200,43.226.58.1,43.226.58.33,24,192.168.99.24 +25,铁岭,lntl197,43.226.58.1,43.226.58.34,24,192.168.99.25 +26,攀枝花,scpzh148,43.226.58.1,43.226.58.35,24,192.168.99.26 +27,自贡,sczg146,43.226.58.1,43.226.58.36,24,192.168.99.27 +28,内江,scnj149,43.226.58.1,43.226.58.37,24,192.168.99.28 +29,成都,sccd157,43.226.58.1,43.226.58.38,24,192.168.99.29 +30,广元,scgy154,43.226.58.1,43.226.58.39,24,192.168.99.30 +31,德阳,scdy155,43.226.58.1,43.226.58.40,24,192.168.99.31 +32,泸州,sclz152,43.226.58.1,43.226.58.41,24,192.168.99.32 +33,乐山,scls153,43.226.58.1,43.226.58.42,24,192.168.99.33 +34,绵阳,scmy151,43.226.58.1,43.226.58.43,24,192.168.99.34 +35,达州,scdz156,43.226.58.1,43.226.58.44,24,192.168.99.35 +36,南充,scnc150,43.226.58.1,43.226.58.45,24,192.168.99.36 +37,宜宾,scyb147,43.226.58.1,43.226.58.46,24,192.168.99.37 +38,保定,hbbd169,43.226.58.1,43.226.58.47,24,192.168.99.38 +39,张家口,hbzjk159,43.226.58.1,43.226.58.48,24,192.168.99.39 +40,沧州,hbcz168,43.226.58.1,43.226.58.49,24,192.168.99.40 +41,秦皇岛,hbqhd163,43.226.58.1,43.226.58.50,24,192.168.99.41 +42,邯郸,hbhd166,43.226.58.1,43.226.58.51,24,192.168.99.42 +43,唐山,hbts161,43.226.58.1,43.226.58.52,24,192.168.99.43 +44,廊坊,hblf164,43.226.58.1,43.226.58.53,24,192.168.99.44 +45,承德,hbcd167,43.226.58.1,43.226.58.54,24,192.168.99.45 +46,石家庄,hbsjz162,43.226.58.1,43.226.58.55,24,192.168.99.46 +47,衡水,hbhs165,43.226.58.1,43.226.58.56,24,192.168.99.47 +48,邢台,hbxt160,43.226.58.1,43.226.58.57,24,192.168.99.48 +49,台州,zjtz135,43.226.58.1,43.226.58.58,24,192.168.99.49 +50,嘉兴,zjjx141,43.226.58.1,43.226.58.59,24,192.168.99.50 +51,宁波,zjnb138,43.226.58.1,43.226.58.60,24,192.168.99.51 +52,杭州,zjhz143,43.226.58.1,43.226.58.61,24,192.168.99.52 +53,绍兴,zjsx136,43.226.58.1,43.226.58.62,24,192.168.99.53 +54,丽水,zjls139,43.226.58.1,43.226.58.63,24,192.168.99.54 +55,温州,zjwz134,43.226.58.1,43.226.58.64,24,192.168.99.55 +56,湖州,zjhz142,43.226.58.1,43.226.58.65,24,192.168.99.56 +57,舟山,zjzs133,43.226.58.1,43.226.58.66,24,192.168.99.57 +58,衢州,zjqz137,43.226.58.1,43.226.58.67,24,192.168.99.58 +59,金华,zjjh140,43.226.58.1,43.226.58.68,24,192.168.99.59 +60,海口,hnhk172,43.226.58.1,43.226.58.69,24,192.168.99.60 +61,文昌,hnwc170,43.226.58.1,43.226.58.70,24,192.168.99.61 +62,三亚,hnsy171,43.226.58.1,43.226.58.71,24,192.168.99.62 +63,上海,sh130,43.226.58.1,43.226.58.72,24,192.168.99.63 +64,昆明,ynkm144,43.226.58.1,43.226.58.73,24,192.168.99.64 +65,呼和浩特,nmghhht192,43.226.58.1,43.226.58.74,24,192.168.99.65 +66,赤峰,nmgcf194,43.226.58.1,43.226.58.75,24,192.168.99.66 +67,鄂尔多斯,nmgeeds193,43.226.58.1,43.226.58.76,24,192.168.99.67 +68,通辽,nmgtl190,43.226.58.1,43.226.58.77,24,192.168.99.68 +69,包头,nmgbt195,43.226.58.1,43.226.58.78,24,192.168.99.69 +70,呼伦贝尔,nmghlbe191,43.226.58.1,43.226.58.79,24,192.168.99.70 +71,南昌,jxnc210,43.226.58.1,43.226.58.80,24,192.168.99.71 +72,鹰潭,jxyt205,43.226.58.1,43.226.58.81,24,192.168.99.72 +73,抚州,jxfz215,43.226.58.1,43.226.58.82,24,192.168.99.73 +74,新余,jxxy207,43.226.58.1,43.226.58.83,24,192.168.99.74 +75,景德镇,jxjdz212,43.226.58.1,43.226.58.84,24,192.168.99.75 +76,萍乡,jxpx209,43.226.58.1,43.226.58.85,24,192.168.99.76 +77,上饶,jxsr208,43.226.58.1,43.226.58.86,24,192.168.99.77 +78,九江,jxjj211,43.226.58.1,43.226.58.87,24,192.168.99.78 +79,吉安,jxja213,43.226.58.1,43.226.58.88,24,192.168.99.79 +80,宜春,jxyc206,43.226.58.1,43.226.58.89,24,192.168.99.80 +81,赣州,jxgz214,43.226.58.1,43.226.58.90,24,192.168.99.81 +82,德州,sddz187,43.226.58.1,43.226.58.91,24,192.168.99.82 +83,淄博,sdzb173,43.226.58.1,43.226.58.92,24,192.168.99.83 +84,潍坊,sdwf176,43.226.58.1,43.226.58.93,24,192.168.99.84 +85,烟台,sdyt175,43.226.58.1,43.226.58.94,24,192.168.99.85 +86,菏泽,sdhz185,43.226.58.1,43.226.58.95,24,192.168.99.86 +87,威海,sdwh177,43.226.58.1,43.226.58.96,24,192.168.99.87 +88,枣庄,sdzz174,43.226.58.1,43.226.58.97,24,192.168.99.88 +89,泰安,sdta178,43.226.58.1,43.226.58.98,24,192.168.99.89 +90,济宁,sdjn183,43.226.58.1,43.226.58.99,24,192.168.99.90 +91,滨州,sdbz188,43.226.58.1,43.226.58.100,24,192.168.99.91 +92,东营,sddy186,43.226.58.1,43.226.58.101,24,192.168.99.92 +93,日照,sdrz179,43.226.58.1,43.226.58.102,24,192.168.99.93 +94,青岛,sdqd180,43.226.58.1,43.226.58.103,24,192.168.99.94 +95,临沂,sdly181,43.226.58.1,43.226.58.104,24,192.168.99.95 +96,济南,sdjn184,43.226.58.1,43.226.58.105,24,192.168.99.96 +97,聊城,sdlc182,43.226.58.1,43.226.58.106,24,192.168.99.97 +98,商丘,hnsq151,43.226.58.1,43.226.58.107,24,192.168.99.98 +99,安阳,hnay158,43.226.58.1,43.226.58.108,24,192.168.99.99 +100,开封,hnkf155,43.226.58.1,43.226.58.109,24,192.168.99.100 +101,新乡,hnxx150,43.226.58.1,43.226.58.110,24,192.168.99.101 +102,洛阳,hnly154,43.226.58.1,43.226.58.111,24,192.168.99.102 +103,信阳,hnxy149,43.226.58.1,43.226.58.112,24,192.168.99.103 +104,周口,hnzk146,43.226.58.1,43.226.58.113,24,192.168.99.104 +105,漯河,hnlh153,43.226.58.1,43.226.58.114,24,192.168.99.105 +106,焦作,hnjz156,43.226.58.1,43.226.58.115,24,192.168.99.106 +107,驻马店,hnzmd145,43.226.58.1,43.226.58.116,24,192.168.99.107 +108,鹤壁,hnhb157,43.226.58.1,43.226.58.117,24,192.168.99.108 +109,郑州,hnzz147,43.226.58.1,43.226.58.118,24,192.168.99.109 +110,南阳,hnny152,43.226.58.1,43.226.58.119,24,192.168.99.110 +111,许昌,hnxc148,43.226.58.1,43.226.58.120,24,192.168.99.111 +112,桂林,gxgl182,43.226.58.1,43.226.58.121,24,192.168.99.112 +113,贵港,gxgg183,43.226.58.1,43.226.58.122,24,192.168.99.113 +114,北海,gxbh184,43.226.58.1,43.226.58.123,24,192.168.99.114 +115,南宁,gxnn180,43.226.58.1,43.226.58.124,24,192.168.99.115 +116,柳州,gxlz181,43.226.58.1,43.226.58.125,24,192.168.99.116 +117,钦州,gxqz179,43.226.58.1,43.226.58.126,24,192.168.99.117 +118,玉林,gxyl178,43.226.58.1,43.226.58.127,24,192.168.99.118 +119,银川,nxyc189,43.226.58.1,43.226.58.128,24,192.168.99.119 +120,大同,sxdt172,43.226.58.1,43.226.58.129,24,192.168.99.120 +121,晋城,sxjc171,43.226.58.1,43.226.58.130,24,192.168.99.121 +122,长治,sxcz163,43.226.58.1,43.226.58.131,24,192.168.99.122 +123,阳泉,sxyq165,43.226.58.1,43.226.58.132,24,192.168.99.123 +124,临汾,sxlf170,43.226.58.1,43.226.58.133,24,192.168.99.124 +125,吕梁,sxll169,43.226.58.1,43.226.58.134,24,192.168.99.125 +126,太原,sxty167,43.226.58.1,43.226.58.135,24,192.168.99.126 +127,忻州,sxxz166,43.226.58.1,43.226.58.136,24,192.168.99.127 +128,朔州,sxsz168,43.226.58.1,43.226.58.137,24,192.168.99.128 +129,运城,sxyc164,43.226.58.1,43.226.58.138,24,192.168.99.129 +130,株洲,hnzz235,43.226.58.1,43.226.58.139,24,192.168.99.130 +131,邵阳,hnsy239,43.226.58.1,43.226.58.140,24,192.168.99.131 +132,郴州,hncz241,43.226.58.1,43.226.58.141,24,192.168.99.132 +133,长沙,hncs236,43.226.58.1,43.226.58.142,24,192.168.99.133 +134,湘潭,hnxt238,43.226.58.1,43.226.58.143,24,192.168.99.134 +135,衡阳,hnhy240,43.226.58.1,43.226.58.144,24,192.168.99.135 +136,岳阳,hnyy237,43.226.58.1,43.226.58.145,24,192.168.99.136 +137,三明,fjsm208,43.226.58.1,43.226.58.146,24,192.168.99.137 +138,南平,fjnp212,43.226.58.1,43.226.58.147,24,192.168.99.138 +139,厦门,fjxm207,43.226.58.1,43.226.58.148,24,192.168.99.139 +140,龙岩,fjly213,43.226.58.1,43.226.58.149,24,192.168.99.140 +141,宁德,fjnd211,43.226.58.1,43.226.58.150,24,192.168.99.141 +142,泉州,fjqz209,43.226.58.1,43.226.58.151,24,192.168.99.142 +143,福州,fjfz214,43.226.58.1,43.226.58.152,24,192.168.99.143 +144,莆田,fjpt210,43.226.58.1,43.226.58.153,24,192.168.99.144 +145,六盘水,gzlps176,43.226.58.1,43.226.58.154,24,192.168.99.145 +146,黔东南,gzqdn175,43.226.58.1,43.226.58.155,24,192.168.99.146 +147,贵阳,gzgy177,43.226.58.1,43.226.58.156,24,192.168.99.147 +148,遵义,gzzy173,43.226.58.1,43.226.58.157,24,192.168.99.148 +149,铜仁,gztr174,43.226.58.1,43.226.58.158,24,192.168.99.149 +150,渭南,sxwn160,43.226.58.1,43.226.58.159,24,192.168.99.150 +151,宝鸡,sxbj162,43.226.58.1,43.226.58.160,24,192.168.99.151 +152,西安,sxxa159,43.226.58.1,43.226.58.161,24,192.168.99.152 +153,铜川,sxtc161,43.226.58.1,43.226.58.162,24,192.168.99.153 +154,咸阳,sxxy158,43.226.58.1,43.226.58.163,24,192.168.99.154 +155,北京,bj129,43.226.58.1,43.226.58.164,24,192.168.99.155 +156,天津,tj131,43.226.58.1,43.226.58.165,24,192.168.99.156 +157,南通,jsnt224,43.226.58.1,43.226.58.166,24,192.168.99.157 +158,宿迁,jssq220,43.226.58.1,43.226.58.167,24,192.168.99.158 +159,常州,jscz228,43.226.58.1,43.226.58.168,24,192.168.99.159 +160,南京,jsnj225,43.226.58.1,43.226.58.169,24,192.168.99.160 +161,泰州,jstz222,43.226.58.1,43.226.58.170,24,192.168.99.161 +162,淮安,jsha227,43.226.58.1,43.226.58.171,24,192.168.99.162 +163,苏州,jssz223,43.226.58.1,43.226.58.172,24,192.168.99.163 +164,连云港,jslyg226,43.226.58.1,43.226.58.173,24,192.168.99.164 +165,无锡,jswx221,43.226.58.1,43.226.58.174,24,192.168.99.165 +166,扬州,jsyz217,43.226.58.1,43.226.58.175,24,192.168.99.166 +167,盐城,jsyc218,43.226.58.1,43.226.58.176,24,192.168.99.167 +168,徐州,jsxz219,43.226.58.1,43.226.58.177,24,192.168.99.168 +169,镇江,jszj216,43.226.58.1,43.226.58.178,24,192.168.99.169 +170,咸宁,hbxn245,43.226.58.1,43.226.58.179,24,192.168.99.170 +171,荆州,hbjz129,43.226.58.1,43.226.58.180,24,192.168.99.171 +172,黄石,hbhs131,43.226.58.1,43.226.58.181,24,192.168.99.172 +173,武汉,hbwh246,43.226.58.1,43.226.58.182,24,192.168.99.173 +174,荆门,hbjm130,43.226.58.1,43.226.58.183,24,192.168.99.174 +175,孝感,hbxg243,43.226.58.1,43.226.58.184,24,192.168.99.175 +176,宜昌,hbyc242,43.226.58.1,43.226.58.185,24,192.168.99.176 +177,襄阳,hbxy244,43.226.58.1,43.226.58.186,24,192.168.99.177 +178,黄冈,hbhg132,43.226.58.1,43.226.58.187,24,192.168.99.178 +179,重庆,cq132,43.226.58.1,43.226.58.188,24,192.168.99.179 +180,白山,jlbs234,43.226.58.1,43.226.58.189,24,192.168.99.180 +181,通化,jlth231,43.226.58.1,43.226.58.190,24,192.168.99.181 +182,松原,jlsy232,43.226.58.1,43.226.58.191,24,192.168.99.182 +183,长春,jlcc229,43.226.58.1,43.226.58.192,24,192.168.99.183 +184,四平,jlsp233,43.226.58.1,43.226.58.193,24,192.168.99.184 +185,延边,jlyb230,43.226.58.1,43.226.58.194,24,192.168.99.185 +186,广州,gdgz202,43.226.58.1,43.226.58.195,24,192.168.99.186 +187,惠州,gdhz200,43.226.58.1,43.226.58.196,24,192.168.99.187 +188,深圳,gdsz191,43.226.58.1,43.226.58.197,24,192.168.99.188 +189,珠海,gdzh185,43.226.58.1,43.226.58.198,24,192.168.99.189 +190,茂名,gdmm197,43.226.58.1,43.226.58.199,24,192.168.99.190 +191,阳江,gdyj190,43.226.58.1,43.226.58.200,24,192.168.99.191 +192,中山,gdzs186,43.226.58.1,43.226.58.201,24,192.168.99.192 +193,云浮,gdyf189,43.226.58.1,43.226.58.202,24,192.168.99.193 +194,揭阳,gdjy198,43.226.58.1,43.226.58.203,24,192.168.99.194 +195,汕头,gdst194,43.226.58.1,43.226.58.204,24,192.168.99.195 +196,韶关,gdsg192,43.226.58.1,43.226.58.205,24,192.168.99.196 +197,潮州,gdcz205,43.226.58.1,43.226.58.206,24,192.168.99.197 +198,佛山,gdfs203,43.226.58.1,43.226.58.207,24,192.168.99.198 +199,汕尾,gdsw193,43.226.58.1,43.226.58.208,24,192.168.99.199 +200,江门,gdjm199,43.226.58.1,43.226.58.209,24,192.168.99.200 +201,河源,gdhy201,43.226.58.1,43.226.58.210,24,192.168.99.201 +202,清远,gdqy195,43.226.58.1,43.226.58.211,24,192.168.99.202 +203,湛江,gdzj188,43.226.58.1,43.226.58.212,24,192.168.99.203 +204,东莞,gddg204,43.226.58.1,43.226.58.213,24,192.168.99.204 +205,梅州,gdmz196,43.226.58.1,43.226.58.214,24,192.168.99.205 +206,肇庆,gdzq187,43.226.58.1,43.226.58.215,24,192.168.99.206 +207,乌鲁木齐,xjwlmq145,43.226.58.1,43.226.58.216,24,192.168.99.207 +208,兰州,gslz206,43.226.58.1,43.226.58.217,24,192.168.99.208 +209,七台河,hljqth137,43.226.58.1,43.226.58.218,24,192.168.99.209 +210,牡丹江,hljmdj138,43.226.58.1,43.226.58.219,24,192.168.99.210 +211,绥化,hljsh134,43.226.58.1,43.226.58.220,24,192.168.99.211 +212,鹤岗,hljhg142,43.226.58.1,43.226.58.221,24,192.168.99.212 +213,双鸭山,hljsys135,43.226.58.1,43.226.58.222,24,192.168.99.213 +214,大庆,hljdq144,43.226.58.1,43.226.58.223,24,192.168.99.214 +215,佳木斯,hljjms139,43.226.58.1,43.226.58.224,24,192.168.99.215 +216,鸡西,hljjx140,43.226.58.1,43.226.58.225,24,192.168.99.216 +217,伊春,hljyc133,43.226.58.1,43.226.58.226,24,192.168.99.217 +218,哈尔滨,hljheb143,43.226.58.1,43.226.58.227,24,192.168.99.218 +219,黑河,hljhh141,43.226.58.1,43.226.58.228,24,192.168.99.219 +220,齐齐哈尔,hljqqhe136,43.226.58.1,43.226.58.229,24,192.168.99.220 diff --git a/config.csv b/config.csv new file mode 100644 index 0000000..28b1323 --- /dev/null +++ b/config.csv @@ -0,0 +1,221 @@ +index,name,code,gateway,public,mask,private +1,宣城,ahxc215,43.226.58.1,43.226.58.10,24,192.168.99.1 +2,宿州,ahsz216,43.226.58.1,43.226.58.11,24,192.168.99.2 +3,阜阳,ahfy225,43.226.58.1,43.226.58.12,24,192.168.99.3 +4,合肥,ahhf224,43.226.58.1,43.226.58.13,24,192.168.99.4 +5,淮南,ahhn222,43.226.58.1,43.226.58.14,24,192.168.99.5 +6,铜陵,ahtl218,43.226.58.1,43.226.58.15,24,192.168.99.6 +7,马鞍山,ahmas219,43.226.58.1,43.226.58.16,24,192.168.99.7 +8,黄山,ahhs221,43.226.58.1,43.226.58.17,24,192.168.99.8 +9,亳州,ahbz228,43.226.58.1,43.226.58.18,24,192.168.99.9 +10,安庆,ahaq230,43.226.58.1,43.226.58.19,24,192.168.99.10 +11,淮北,ahhb223,43.226.58.1,43.226.58.20,24,192.168.99.11 +12,滁州,ahcz226,43.226.58.1,43.226.58.21,24,192.168.99.12 +13,芜湖,ahwh217,43.226.58.1,43.226.58.22,24,192.168.99.13 +14,六安,ahla220,43.226.58.1,43.226.58.23,24,192.168.99.14 +15,蚌埠,ahbb229,43.226.58.1,43.226.58.24,24,192.168.99.15 +16,池州,ahchz227,43.226.58.1,43.226.58.25,24,192.168.99.16 +17,营口,lnlyk196,43.226.58.1,43.226.58.26,24,192.168.99.17 +18,鞍山,lnas204,43.226.58.1,43.226.58.27,24,192.168.99.18 +19,抚顺,lnfs201,43.226.58.1,43.226.58.28,24,192.168.99.19 +20,沈阳,lnsy198,43.226.58.1,43.226.58.29,24,192.168.99.20 +21,大连,lndl202,43.226.58.1,43.226.58.30,24,192.168.99.21 +22,朝阳,lncy203,43.226.58.1,43.226.58.31,24,192.168.99.22 +23,盘锦,lnpj199,43.226.58.1,43.226.58.32,24,192.168.99.23 +24,葫芦岛,lnhld200,43.226.58.1,43.226.58.33,24,192.168.99.24 +25,铁岭,lntl197,43.226.58.1,43.226.58.34,24,192.168.99.25 +26,攀枝花,scpzh148,43.226.58.1,43.226.58.35,24,192.168.99.26 +27,自贡,sczg146,43.226.58.1,43.226.58.36,24,192.168.99.27 +28,内江,scnj149,43.226.58.1,43.226.58.37,24,192.168.99.28 +29,成都,sccd157,43.226.58.1,43.226.58.38,24,192.168.99.29 +30,广元,scgy154,43.226.58.1,43.226.58.39,24,192.168.99.30 +31,德阳,scdy155,43.226.58.1,43.226.58.40,24,192.168.99.31 +32,泸州,sclz152,43.226.58.1,43.226.58.41,24,192.168.99.32 +33,乐山,scls153,43.226.58.1,43.226.58.42,24,192.168.99.33 +34,绵阳,scmy151,43.226.58.1,43.226.58.43,24,192.168.99.34 +35,达州,scdz156,43.226.58.1,43.226.58.44,24,192.168.99.35 +36,南充,scnc150,43.226.58.1,43.226.58.45,24,192.168.99.36 +37,宜宾,scyb147,43.226.58.1,43.226.58.46,24,192.168.99.37 +38,保定,hbbd169,43.226.58.1,43.226.58.47,24,192.168.99.38 +39,张家口,hbzjk159,43.226.58.1,43.226.58.48,24,192.168.99.39 +40,沧州,hbcz168,43.226.58.1,43.226.58.49,24,192.168.99.40 +41,秦皇岛,hbqhd163,43.226.58.1,43.226.58.50,24,192.168.99.41 +42,邯郸,hbhd166,43.226.58.1,43.226.58.51,24,192.168.99.42 +43,唐山,hbts161,43.226.58.1,43.226.58.52,24,192.168.99.43 +44,廊坊,hblf164,43.226.58.1,43.226.58.53,24,192.168.99.44 +45,承德,hbcd167,43.226.58.1,43.226.58.54,24,192.168.99.45 +46,石家庄,hbsjz162,43.226.58.1,43.226.58.55,24,192.168.99.46 +47,衡水,hbhs165,43.226.58.1,43.226.58.56,24,192.168.99.47 +48,邢台,hbxt160,43.226.58.1,43.226.58.57,24,192.168.99.48 +49,台州,zjtz135,43.226.58.1,43.226.58.58,24,192.168.99.49 +50,嘉兴,zjjx141,43.226.58.1,43.226.58.59,24,192.168.99.50 +51,宁波,zjnb138,43.226.58.1,43.226.58.60,24,192.168.99.51 +52,杭州,zjhz143,43.226.58.1,43.226.58.61,24,192.168.99.52 +53,绍兴,zjsx136,43.226.58.1,43.226.58.62,24,192.168.99.53 +54,丽水,zjls139,43.226.58.1,43.226.58.63,24,192.168.99.54 +55,温州,zjwz134,43.226.58.1,43.226.58.64,24,192.168.99.55 +56,湖州,zjhz142,43.226.58.1,43.226.58.65,24,192.168.99.56 +57,舟山,zjzs133,43.226.58.1,43.226.58.66,24,192.168.99.57 +58,衢州,zjqz137,43.226.58.1,43.226.58.67,24,192.168.99.58 +59,金华,zjjh140,43.226.58.1,43.226.58.68,24,192.168.99.59 +60,海口,hnhk172,43.226.58.1,43.226.58.69,24,192.168.99.60 +61,文昌,hnwc170,43.226.58.1,43.226.58.70,24,192.168.99.61 +62,三亚,hnsy171,43.226.58.1,43.226.58.71,24,192.168.99.62 +63,上海,sh130,43.226.58.1,43.226.58.72,24,192.168.99.63 +64,昆明,ynkm144,43.226.58.1,43.226.58.73,24,192.168.99.64 +65,呼和浩特,nmghhht192,43.226.58.1,43.226.58.74,24,192.168.99.65 +66,赤峰,nmgcf194,43.226.58.1,43.226.58.75,24,192.168.99.66 +67,鄂尔多斯,nmgeeds193,43.226.58.1,43.226.58.76,24,192.168.99.67 +68,通辽,nmgtl190,43.226.58.1,43.226.58.77,24,192.168.99.68 +69,包头,nmgbt195,43.226.58.1,43.226.58.78,24,192.168.99.69 +70,呼伦贝尔,nmghlbe191,43.226.58.1,43.226.58.79,24,192.168.99.70 +71,南昌,jxnc210,43.226.58.1,43.226.58.80,24,192.168.99.71 +72,鹰潭,jxyt205,43.226.58.1,43.226.58.81,24,192.168.99.72 +73,抚州,jxfz215,43.226.58.1,43.226.58.82,24,192.168.99.73 +74,新余,jxxy207,43.226.58.1,43.226.58.83,24,192.168.99.74 +75,景德镇,jxjdz212,43.226.58.1,43.226.58.84,24,192.168.99.75 +76,萍乡,jxpx209,43.226.58.1,43.226.58.85,24,192.168.99.76 +77,上饶,jxsr208,43.226.58.1,43.226.58.86,24,192.168.99.77 +78,九江,jxjj211,43.226.58.1,43.226.58.87,24,192.168.99.78 +79,吉安,jxja213,43.226.58.1,43.226.58.88,24,192.168.99.79 +80,宜春,jxyc206,43.226.58.1,43.226.58.89,24,192.168.99.80 +81,赣州,jxgz214,43.226.58.1,43.226.58.90,24,192.168.99.81 +82,德州,sddz187,43.226.58.1,43.226.58.91,24,192.168.99.82 +83,淄博,sdzb173,43.226.58.1,43.226.58.92,24,192.168.99.83 +84,潍坊,sdwf176,43.226.58.1,43.226.58.93,24,192.168.99.84 +85,烟台,sdyt175,43.226.58.1,43.226.58.94,24,192.168.99.85 +86,菏泽,sdhz185,43.226.58.1,43.226.58.95,24,192.168.99.86 +87,威海,sdwh177,43.226.58.1,43.226.58.96,24,192.168.99.87 +88,枣庄,sdzz174,43.226.58.1,43.226.58.97,24,192.168.99.88 +89,泰安,sdta178,43.226.58.1,43.226.58.98,24,192.168.99.89 +90,济宁,sdjn183,43.226.58.1,43.226.58.99,24,192.168.99.90 +91,滨州,sdbz188,43.226.58.1,43.226.58.100,24,192.168.99.91 +92,东营,sddy186,43.226.58.1,43.226.58.101,24,192.168.99.92 +93,日照,sdrz179,43.226.58.1,43.226.58.102,24,192.168.99.93 +94,青岛,sdqd180,43.226.58.1,43.226.58.103,24,192.168.99.94 +95,临沂,sdly181,43.226.58.1,43.226.58.104,24,192.168.99.95 +96,济南,sdjn184,43.226.58.1,43.226.58.105,24,192.168.99.96 +97,聊城,sdlc182,43.226.58.1,43.226.58.106,24,192.168.99.97 +98,商丘,hnsq151,43.226.58.1,43.226.58.107,24,192.168.99.98 +99,安阳,hnay158,43.226.58.1,43.226.58.108,24,192.168.99.99 +100,开封,hnkf155,43.226.58.1,43.226.58.109,24,192.168.99.100 +101,新乡,hnxx150,43.226.58.1,43.226.58.110,24,192.168.99.101 +102,洛阳,hnly154,43.226.58.1,43.226.58.111,24,192.168.99.102 +103,信阳,hnxy149,43.226.58.1,43.226.58.112,24,192.168.99.103 +104,周口,hnzk146,43.226.58.1,43.226.58.113,24,192.168.99.104 +105,漯河,hnlh153,43.226.58.1,43.226.58.114,24,192.168.99.105 +106,焦作,hnjz156,43.226.58.1,43.226.58.115,24,192.168.99.106 +107,驻马店,hnzmd145,43.226.58.1,43.226.58.116,24,192.168.99.107 +108,鹤壁,hnhb157,43.226.58.1,43.226.58.117,24,192.168.99.108 +109,郑州,hnzz147,43.226.58.1,43.226.58.118,24,192.168.99.109 +110,南阳,hnny152,43.226.58.1,43.226.58.119,24,192.168.99.110 +111,许昌,hnxc148,43.226.58.1,43.226.58.120,24,192.168.99.111 +112,桂林,gxgl182,43.226.58.1,43.226.58.121,24,192.168.99.112 +113,贵港,gxgg183,43.226.58.1,43.226.58.122,24,192.168.99.113 +114,北海,gxbh184,43.226.58.1,43.226.58.123,24,192.168.99.114 +115,南宁,gxnn180,43.226.58.1,43.226.58.124,24,192.168.99.115 +116,柳州,gxlz181,43.226.58.1,43.226.58.125,24,192.168.99.116 +117,钦州,gxqz179,43.226.58.1,43.226.58.126,24,192.168.99.117 +118,玉林,gxyl178,43.226.58.1,43.226.58.127,24,192.168.99.118 +119,银川,nxyc189,43.226.58.1,43.226.58.128,24,192.168.99.119 +120,大同,sxdt172,43.226.58.1,43.226.58.129,24,192.168.99.120 +121,晋城,sxjc171,43.226.58.1,43.226.58.130,24,192.168.99.121 +122,长治,sxcz163,43.226.58.1,43.226.58.131,24,192.168.99.122 +123,阳泉,sxyq165,43.226.58.1,43.226.58.132,24,192.168.99.123 +124,临汾,sxlf170,43.226.58.1,43.226.58.133,24,192.168.99.124 +125,吕梁,sxll169,43.226.58.1,43.226.58.134,24,192.168.99.125 +126,太原,sxty167,43.226.58.1,43.226.58.135,24,192.168.99.126 +127,忻州,sxxz166,43.226.58.1,43.226.58.136,24,192.168.99.127 +128,朔州,sxsz168,43.226.58.1,43.226.58.137,24,192.168.99.128 +129,运城,sxyc164,43.226.58.1,43.226.58.138,24,192.168.99.129 +130,株洲,hnzz235,43.226.58.1,43.226.58.139,24,192.168.99.130 +131,邵阳,hnsy239,43.226.58.1,43.226.58.140,24,192.168.99.131 +132,郴州,hncz241,43.226.58.1,43.226.58.141,24,192.168.99.132 +133,长沙,hncs236,43.226.58.1,43.226.58.142,24,192.168.99.133 +134,湘潭,hnxt238,43.226.58.1,43.226.58.143,24,192.168.99.134 +135,衡阳,hnhy240,43.226.58.1,43.226.58.144,24,192.168.99.135 +136,岳阳,hnyy237,43.226.58.1,43.226.58.145,24,192.168.99.136 +137,三明,fjsm208,43.226.58.1,43.226.58.146,24,192.168.99.137 +138,南平,fjnp212,43.226.58.1,43.226.58.147,24,192.168.99.138 +139,厦门,fjxm207,43.226.58.1,43.226.58.148,24,192.168.99.139 +140,龙岩,fjly213,43.226.58.1,43.226.58.149,24,192.168.99.140 +141,宁德,fjnd211,43.226.58.1,43.226.58.150,24,192.168.99.141 +142,泉州,fjqz209,43.226.58.1,43.226.58.151,24,192.168.99.142 +143,福州,fjfz214,43.226.58.1,43.226.58.152,24,192.168.99.143 +144,莆田,fjpt210,43.226.58.1,43.226.58.153,24,192.168.99.144 +145,六盘水,gzlps176,43.226.58.1,43.226.58.154,24,192.168.99.145 +146,黔东南,gzqdn175,43.226.58.1,43.226.58.155,24,192.168.99.146 +147,贵阳,gzgy177,43.226.58.1,43.226.58.156,24,192.168.99.147 +148,遵义,gzzy173,43.226.58.1,43.226.58.157,24,192.168.99.148 +149,铜仁,gztr174,43.226.58.1,43.226.58.158,24,192.168.99.149 +150,渭南,sxwn160,43.226.58.1,43.226.58.159,24,192.168.99.150 +151,宝鸡,sxbj162,43.226.58.1,43.226.58.160,24,192.168.99.151 +152,西安,sxxa159,43.226.58.1,43.226.58.161,24,192.168.99.152 +153,铜川,sxtc161,43.226.58.1,43.226.58.162,24,192.168.99.153 +154,咸阳,sxxy158,43.226.58.1,43.226.58.163,24,192.168.99.154 +155,北京,bj129,43.226.58.1,43.226.58.164,24,192.168.99.155 +156,天津,tj131,43.226.58.1,43.226.58.165,24,192.168.99.156 +157,南通,jsnt224,43.226.58.1,43.226.58.166,24,192.168.99.157 +158,宿迁,jssq220,43.226.58.1,43.226.58.167,24,192.168.99.158 +159,常州,jscz228,43.226.58.1,43.226.58.168,24,192.168.99.159 +160,南京,jsnj225,43.226.58.1,43.226.58.169,24,192.168.99.160 +161,泰州,jstz222,43.226.58.1,43.226.58.170,24,192.168.99.161 +162,淮安,jsha227,43.226.58.1,43.226.58.171,24,192.168.99.162 +163,苏州,jssz223,43.226.58.1,43.226.58.172,24,192.168.99.163 +164,连云港,jslyg226,43.226.58.1,43.226.58.173,24,192.168.99.164 +165,无锡,jswx221,43.226.58.1,43.226.58.174,24,192.168.99.165 +166,扬州,jsyz217,43.226.58.1,43.226.58.175,24,192.168.99.166 +167,盐城,jsyc218,43.226.58.1,43.226.58.176,24,192.168.99.167 +168,徐州,jsxz219,43.226.58.1,43.226.58.177,24,192.168.99.168 +169,镇江,jszj216,43.226.58.1,43.226.58.178,24,192.168.99.169 +170,咸宁,hbxn245,43.226.58.1,43.226.58.179,24,192.168.99.170 +171,荆州,hbjz129,43.226.58.1,43.226.58.180,24,192.168.99.171 +172,黄石,hbhs131,43.226.58.1,43.226.58.181,24,192.168.99.172 +173,武汉,hbwh246,43.226.58.1,43.226.58.182,24,192.168.99.173 +174,荆门,hbjm130,43.226.58.1,43.226.58.183,24,192.168.99.174 +175,孝感,hbxg243,43.226.58.1,43.226.58.184,24,192.168.99.175 +176,宜昌,hbyc242,43.226.58.1,43.226.58.185,24,192.168.99.176 +177,襄阳,hbxy244,43.226.58.1,43.226.58.186,24,192.168.99.177 +178,黄冈,hbhg132,43.226.58.1,43.226.58.187,24,192.168.99.178 +179,重庆,cq132,43.226.58.1,43.226.58.188,24,192.168.99.179 +180,白山,jlbs234,43.226.58.1,43.226.58.189,24,192.168.99.180 +181,通化,jlth231,43.226.58.1,43.226.58.190,24,192.168.99.181 +182,松原,jlsy232,43.226.58.1,43.226.58.191,24,192.168.99.182 +183,长春,jlcc229,43.226.58.1,43.226.58.192,24,192.168.99.183 +184,四平,jlsp233,43.226.58.1,43.226.58.193,24,192.168.99.184 +185,延边,jlyb230,43.226.58.1,43.226.58.194,24,192.168.99.185 +186,广州,gdgz202,43.226.58.1,43.226.58.195,24,192.168.99.186 +187,惠州,gdhz200,43.226.58.1,43.226.58.196,24,192.168.99.187 +188,深圳,gdsz191,43.226.58.1,43.226.58.197,24,192.168.99.188 +189,珠海,gdzh185,43.226.58.1,43.226.58.198,24,192.168.99.189 +190,茂名,gdmm197,43.226.58.1,43.226.58.199,24,192.168.99.190 +191,阳江,gdyj190,43.226.58.1,43.226.58.200,24,192.168.99.191 +192,中山,gdzs186,43.226.58.1,43.226.58.201,24,192.168.99.192 +193,云浮,gdyf189,43.226.58.1,43.226.58.202,24,192.168.99.193 +194,揭阳,gdjy198,43.226.58.1,43.226.58.203,24,192.168.99.194 +195,汕头,gdst194,43.226.58.1,43.226.58.204,24,192.168.99.195 +196,韶关,gdsg192,43.226.58.1,43.226.58.205,24,192.168.99.196 +197,潮州,gdcz205,43.226.58.1,43.226.58.206,24,192.168.99.197 +198,佛山,gdfs203,43.226.58.1,43.226.58.207,24,192.168.99.198 +199,汕尾,gdsw193,43.226.58.1,43.226.58.208,24,192.168.99.199 +200,江门,gdjm199,43.226.58.1,43.226.58.209,24,192.168.99.200 +201,河源,gdhy201,43.226.58.1,43.226.58.210,24,192.168.99.201 +202,清远,gdqy195,43.226.58.1,43.226.58.211,24,192.168.99.202 +203,湛江,gdzj188,43.226.58.1,43.226.58.212,24,192.168.99.203 +204,东莞,gddg204,43.226.58.1,43.226.58.213,24,192.168.99.204 +205,梅州,gdmz196,43.226.58.1,43.226.58.214,24,192.168.99.205 +206,肇庆,gdzq187,43.226.58.1,43.226.58.215,24,192.168.99.206 +207,乌鲁木齐,xjwlmq145,43.226.58.1,43.226.58.216,24,192.168.99.207 +208,兰州,gslz206,43.226.58.1,43.226.58.217,24,192.168.99.208 +209,七台河,hljqth137,43.226.58.1,43.226.58.218,24,192.168.99.209 +210,牡丹江,hljmdj138,43.226.58.1,43.226.58.219,24,192.168.99.210 +211,绥化,hljsh134,43.226.58.1,43.226.58.220,24,192.168.99.211 +212,鹤岗,hljhg142,43.226.58.1,43.226.58.221,24,192.168.99.212 +213,双鸭山,hljsys135,43.226.58.1,43.226.58.222,24,192.168.99.213 +214,大庆,hljdq144,43.226.58.1,43.226.58.223,24,192.168.99.214 +215,佳木斯,hljjms139,43.226.58.1,43.226.58.224,24,192.168.99.215 +216,鸡西,hljjx140,43.226.58.1,43.226.58.225,24,192.168.99.216 +217,伊春,hljyc133,43.226.58.1,43.226.58.226,24,192.168.99.217 +218,哈尔滨,hljheb143,43.226.58.1,43.226.58.227,24,192.168.99.218 +219,黑河,hljhh141,43.226.58.1,43.226.58.228,24,192.168.99.219 +220,齐齐哈尔,hljqqhe136,43.226.58.1,43.226.58.229,24,192.168.99.220 diff --git a/main.py b/main.py new file mode 100644 index 0000000..998fcd1 --- /dev/null +++ b/main.py @@ -0,0 +1,310 @@ +from librouteros import connect,Api +import csv +import ssl +import threading + +''' +自动配置 ros 脚本,需要安装 librouteros 库: + +pip install librouteros + +配置文件格式为 CSV,包含以下字段: + +- index: 配置索引,【重要】这个 index 用来生成对应 l2tp-out 用户名中的序号,每个节点都是唯一且固定的 +- name: 城市名 +- code: 城市代码 +- gateway: 网关地址 +- public: 公网 IP +- mask: 公网子网掩码 +- private: 内网 IP + +如果需要添加或修改配置项,在编辑前记得先备份 config.csv 文件 + +如果需要修改配置内容,在 start 函数里 “配置 ros” 部分添加或修改函数调用 +''' + +threads = [] +failed = [] + +def main(): + # 加载配置文件 + config_data = [] + with open('config.csv', 'r', encoding='utf-8-sig') as file: + reader = csv.DictReader(file) + for row in reader: + config_data.append(row) + + # 多线程执行 ros 配置 + for _, config in enumerate(config_data): + thread = threading.Thread(target=start, args=(config,)) + thread.start() + threads.append(thread) + + # 等待所有线程完成 + for thread in threads: + thread.join() + + # 输出结果 + print('=' * 20) + print('配置完成统计({}/{}), 失败项:{}'.format(len(config_data)-len(failed), len(config_data), len(failed))) + for _, (item, err) in enumerate(failed): + print('{},{},{},{}'.format(item['public'], item['name'], item['code'], err)) + +def start(config): + print('{}: 配置{}({})'.format(str(config['index']).zfill(3), config['name'], config['code'])) + + # 连接到 ros + conn: Api + try: + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.load_verify_locations('server.crt') + conn = connect( + username='admin', + password='wyongk9815', + host=config['public'], + port=8729, + ssl_wrapper=ctx.wrap_socket, + ) + except Exception as err: + failed.append((config, err)) + return + + # 配置 ros + try: + configLogs(conn, config) + except Exception as err: + failed.append((config, err)) + + # 关闭连接 + conn.close() + + +def configDefault(conn:Api,config): + configNet(conn, config) + configOuts(conn, config) + configScripts(conn, config) + configLogs(conn, config) + + +def configNet(conn:Api,config): + ''' + 配置网络 + ''' + + # 配置路由 + routes = conn.path('ip', 'route') + for route in routes: + if route['routing-table'] == '1': + try: + routes.update(**{ + '.id': route['.id'], + 'gateway': config['gateway'] + }) + except Exception as e: + print('更新默认路由失败: {}'.format(e)) + continue + + # 配置地址 + addrs = conn.path('ip', 'address') + for addr in addrs: + if addr['interface'] == 'lan': + try: + addrs.update(**{ + '.id': addr['.id'], + 'address': config['private'] + }) + except Exception as e: + print('更新 WAN 地址失败: {}'.format(e)) + continue + + # 刷新 mac 地址 + eths = conn.path('interface', 'ethernet') + for eth in eths: + if eth['name'] == 'lan': + tuple(eths('reset-mac-address', **{ + '.id': eth['.id'] + })) + +def configOuts(conn:Api,config): + ''' + 配置 vpn 出口负载均衡 + ''' + count = 20 + + # 配置 ppp + ppps = conn.path('interface', 'l2tp-client') + + # 删除旧的 ppp + for ppp in ppps: + if ppp['name'].startswith('l2tp-out'): + try: + ppps.remove(ppp['.id']) + except Exception as e: + print('删除 PPP 失败: {}'.format(e)) + continue + + # 添加新的 ppp + for i in range(1, count+1): + ppps.add(**{ + 'name':'l2tp-out{}'.format(i), + 'connect-to':'192.168.25{}.25{}'.format((i-1)%3+1, (i-1)%3+1), + 'user':'jdzz{}dt{}'.format(i, config['index']), + 'password':'123231', + 'disabled':'no', + }) + + + # 配置路由 + routes = conn.path('ip', 'route') + + # 删除旧的路由表 + for route in routes: + if str(route['routing-table']).startswith('r'): + try: + routes.remove(route['.id']) + except Exception as e: + print('删除路由表失败: {}'.format(e)) + continue + + # 添加新的路由表 + for i in range(1,count+1): + routeName = 'r{}'.format(i) + routeOut = 'l2tp-out{}'.format(i) + try: + routes.add(**{ + 'dst-address': '0.0.0.0/0', + 'gateway': routeOut, + 'routing-table': routeName, + }) + except Exception as e: + print('添加路由表失败: {}'.format(e)) + continue + +def configScripts(conn:Api,config): + ''' + 配置脚本 + ''' + + scripts = conn.path('system', 'script') + for script in scripts: + if script['name'] == 'up': + with open('scripts/up.rsc', 'rb') as file: + upScript = str(file.read(), encoding='utf-8') + scripts.update(**{ + '.id': script['.id'], + 'source': upScript + }) + elif script['name'] == 'down': + with open('scripts/down.rsc', 'rb') as file: + downScript = str(file.read(), encoding='utf-8') + scripts.update(**{ + '.id': script['.id'], + 'source': downScript + }) + elif script['name'] == 'onlinestatus': + with open('scripts/onlinestatus.rsc', 'rb') as file: + onlineStatusScript = str(file.read(), encoding='utf-8') + scripts.update(**{ + '.id': script['.id'], + 'source': onlineStatusScript.replace('', config['public']) + }) + elif script['name'] == 'pppoestatus': + with open('scripts/pppoestatus.rsc', 'rb') as file: + pppoeStatusScript = str(file.read(), encoding='utf-8') + scripts.update(**{ + '.id': script['.id'], + 'source': pppoeStatusScript.replace('', config['public']) + }) + +def configLogs(conn:Api,config): + ''' + 配置日志处理 + ''' + + # 添加日志过滤器 + filters = conn.path('ip', 'firewall', 'filter') + for filter in filters: + if filter['comment'] == 'natlog': + try: + filters.remove(filter['.id']) + except Exception as e: + print('删除过滤器失败: {}'.format(e)) + continue + + filters.add(**{ + 'chain': 'forward', + 'action': 'log', + 'comment': 'natlog', + 'dst-address': '10.0.0.0/8', + 'protocol': 'tcp', + 'connection-nat-state': 'srcnat', + 'tcp-flags': 'syn', + }) + + filters.add(**{ + 'chain': 'forward', + 'action': 'log', + 'comment': 'natlog', + 'src-address': '10.0.0.0/8', + 'protocol': 'udp', + 'dst-port': '!53', + 'connection-nat-state': '!srcnat', + }) + + # 添加日志动作 + actions = conn.path('system', 'logging', 'action') + + for action in actions: + if action['name'] in ['logremote', 'logremoteidc']: + try: + actions.remove(action['.id']) + except Exception as e: + print('删除日志动作失败: {}'.format(e)) + continue + + actions.add(**{ + 'name': 'logremote', + 'target': 'remote', + 'src-address': '0.0.0.0', + 'remote': '106.119.167.38', + 'remote-port': '5775', + }) + + actions.add(**{ + 'name': 'logremoteidc', + 'target': 'remote', + 'src-address': '0.0.0.0', + 'remote': '192.168.100.255', + 'remote-port': '5775', + }) + + # 配置日志动作 + logs = conn.path('system', 'logging') + + for log in logs: + if 'firewall' in log['topics'] and 'info' in log['topics']: + try: + logs.remove(log['.id']) + except Exception as e: + print('删除日志配置失败: {}'.format(e)) + continue + + logs.add(**{ + 'topics': 'firewall,info', + 'prefix': config['code'], + 'action': 'logremote', + }) + + logs.add(**{ + 'topics': 'firewall,info', + 'prefix': config['code'], + 'action': 'logremoteidc', + }) + +def configDebug(conn:Api,config): + ''' + 配置调试 + ''' + +main() \ No newline at end of file diff --git a/scripts/down.rsc b/scripts/down.rsc new file mode 100644 index 0000000..d099020 --- /dev/null +++ b/scripts/down.rsc @@ -0,0 +1,13 @@ +:local rtable [/ip firewall mangle get [/ip firewall mangle find src-address=$"remote-address"] new-routing-mark] +:local num [:pick $rtable begin=1 end=[:len ($rtable)]] + +:local count [:len [/ip firewall mangle find new-routing-mark="r$num"]] + +/ip firewall mangle remove [/ip firewall mangle find src-address=$"remote-address"] + +:if ($count < 2) do={ + :local localips [/ip address get [/ip address find interface="l2tp-out$num"] address ] + :local localip [:pick $"localips" begin=0 end=([:find $"localips" "/"])] + /tool fetch url="http://192.168.250.250:18702/server/ros/down/ip/$localip" mode=http + /file remove "$localip" +} \ No newline at end of file diff --git a/scripts/onlinestatus.rsc b/scripts/onlinestatus.rsc new file mode 100644 index 0000000..574aebc --- /dev/null +++ b/scripts/onlinestatus.rsc @@ -0,0 +1,4 @@ +:local ddns1 "" +:local num [:len [/ppp active find ]] +/tool fetch url="http://124.236.113.166:18702/script/connect/online.php?num=$num&nasip=$ddns1" mode=http +/file remove "online.php?num=$num&nasip=$ddns1" \ No newline at end of file diff --git a/scripts/pppoestatus.rsc b/scripts/pppoestatus.rsc new file mode 100644 index 0000000..904fc52 --- /dev/null +++ b/scripts/pppoestatus.rsc @@ -0,0 +1,4 @@ +:local ddns1 "" +:local num [:len [/interface l2tp-client find running =yes ]] +/tool fetch url="http://124.236.113.166:18702/script/connect/pppoe.php?num=$num&nasip=$ddns1" mode=http +/file remove "pppoe.php?num=$num&nasip=$ddns1" \ No newline at end of file diff --git a/scripts/up.rsc b/scripts/up.rsc new file mode 100644 index 0000000..1e4f904 --- /dev/null +++ b/scripts/up.rsc @@ -0,0 +1,19 @@ +:local num [/system script get num source] +:local count [:len [/interface l2tp-client find ]] +:local pnum 0 + +:set pnum ($num+1) +/system script set num source="$pnum" + +:if ($num>$count) do={ + :set num 1 + /system script set num source="1" +} + +/ip firewall mangle add action=mark-routing chain=prerouting new-routing-mark="r$num" src-address=$"remote-address" + +:local localips [/ip address get [/ip address find interface="l2tp-out$num"] address ] +:local localip [:pick $"localips" begin=0 end=([:find $"localips" "/"])] + +/tool fetch url="http://192.168.250.250:18702/server/ros/up/ip/$localip" mode=http +/file remove "$localip" \ No newline at end of file