automated DNS-based routing
This commit is contained in:
13
Pipfile
13
Pipfile
@@ -1,13 +0,0 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
paramiko = "*"
|
||||
dnspython = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.10"
|
||||
196
Pipfile.lock
generated
196
Pipfile.lock
generated
@@ -1,196 +0,0 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "34ed4f00e0027cbf1a80ac0f94618d55db4928210629e6dba196cfeb274bc99f"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.10"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"bcrypt": {
|
||||
"hashes": [
|
||||
"sha256:089098effa1bc35dc055366740a067a2fc76987e8ec75349eb9484061c54f535",
|
||||
"sha256:08d2947c490093a11416df18043c27abe3921558d2c03e2076ccb28a116cb6d0",
|
||||
"sha256:0eaa47d4661c326bfc9d08d16debbc4edf78778e6aaba29c1bc7ce67214d4410",
|
||||
"sha256:27d375903ac8261cfe4047f6709d16f7d18d39b1ec92aaf72af989552a650ebd",
|
||||
"sha256:2b3ac11cf45161628f1f3733263e63194f22664bf4d0c0f3ab34099c02134665",
|
||||
"sha256:2caffdae059e06ac23fce178d31b4a702f2a3264c20bfb5ff541b338194d8fab",
|
||||
"sha256:3100851841186c25f127731b9fa11909ab7b1df6fc4b9f8353f4f1fd952fbf71",
|
||||
"sha256:5ad4d32a28b80c5fa6671ccfb43676e8c1cc232887759d1cd7b6f56ea4355215",
|
||||
"sha256:67a97e1c405b24f19d08890e7ae0c4f7ce1e56a712a016746c8b2d7732d65d4b",
|
||||
"sha256:705b2cea8a9ed3d55b4491887ceadb0106acf7c6387699fca771af56b1cdeeda",
|
||||
"sha256:8a68f4341daf7522fe8d73874de8906f3a339048ba406be6ddc1b3ccb16fc0d9",
|
||||
"sha256:a522427293d77e1c29e303fc282e2d71864579527a04ddcfda6d4f8396c6c36a",
|
||||
"sha256:ae88eca3024bb34bb3430f964beab71226e761f51b912de5133470b649d82344",
|
||||
"sha256:b1023030aec778185a6c16cf70f359cbb6e0c289fd564a7cfa29e727a1c38f8f",
|
||||
"sha256:b3b85202d95dd568efcb35b53936c5e3b3600c7cdcc6115ba461df3a8e89f38d",
|
||||
"sha256:b57adba8a1444faf784394de3436233728a1ecaeb6e07e8c22c8848f179b893c",
|
||||
"sha256:bf4fa8b2ca74381bb5442c089350f09a3f17797829d958fad058d6e44d9eb83c",
|
||||
"sha256:ca3204d00d3cb2dfed07f2d74a25f12fc12f73e606fcaa6975d1f7ae69cacbb2",
|
||||
"sha256:cbb03eec97496166b704ed663a53680ab57c5084b2fc98ef23291987b525cb7d",
|
||||
"sha256:e9a51bbfe7e9802b5f3508687758b564069ba937748ad7b9e890086290d2f79e",
|
||||
"sha256:fbdaec13c5105f0c4e5c52614d04f0bca5f5af007910daa8b6b12095edaa67b3"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==4.0.1"
|
||||
},
|
||||
"cffi": {
|
||||
"hashes": [
|
||||
"sha256:00a9ed42e88df81ffae7a8ab6d9356b371399b91dbdf0c3cb1e84c03a13aceb5",
|
||||
"sha256:03425bdae262c76aad70202debd780501fabeaca237cdfddc008987c0e0f59ef",
|
||||
"sha256:04ed324bda3cda42b9b695d51bb7d54b680b9719cfab04227cdd1e04e5de3104",
|
||||
"sha256:0e2642fe3142e4cc4af0799748233ad6da94c62a8bec3a6648bf8ee68b1c7426",
|
||||
"sha256:173379135477dc8cac4bc58f45db08ab45d228b3363adb7af79436135d028405",
|
||||
"sha256:198caafb44239b60e252492445da556afafc7d1e3ab7a1fb3f0584ef6d742375",
|
||||
"sha256:1e74c6b51a9ed6589199c787bf5f9875612ca4a8a0785fb2d4a84429badaf22a",
|
||||
"sha256:2012c72d854c2d03e45d06ae57f40d78e5770d252f195b93f581acf3ba44496e",
|
||||
"sha256:21157295583fe8943475029ed5abdcf71eb3911894724e360acff1d61c1d54bc",
|
||||
"sha256:2470043b93ff09bf8fb1d46d1cb756ce6132c54826661a32d4e4d132e1977adf",
|
||||
"sha256:285d29981935eb726a4399badae8f0ffdff4f5050eaa6d0cfc3f64b857b77185",
|
||||
"sha256:30d78fbc8ebf9c92c9b7823ee18eb92f2e6ef79b45ac84db507f52fbe3ec4497",
|
||||
"sha256:320dab6e7cb2eacdf0e658569d2575c4dad258c0fcc794f46215e1e39f90f2c3",
|
||||
"sha256:33ab79603146aace82c2427da5ca6e58f2b3f2fb5da893ceac0c42218a40be35",
|
||||
"sha256:3548db281cd7d2561c9ad9984681c95f7b0e38881201e157833a2342c30d5e8c",
|
||||
"sha256:3799aecf2e17cf585d977b780ce79ff0dc9b78d799fc694221ce814c2c19db83",
|
||||
"sha256:39d39875251ca8f612b6f33e6b1195af86d1b3e60086068be9cc053aa4376e21",
|
||||
"sha256:3b926aa83d1edb5aa5b427b4053dc420ec295a08e40911296b9eb1b6170f6cca",
|
||||
"sha256:3bcde07039e586f91b45c88f8583ea7cf7a0770df3a1649627bf598332cb6984",
|
||||
"sha256:3d08afd128ddaa624a48cf2b859afef385b720bb4b43df214f85616922e6a5ac",
|
||||
"sha256:3eb6971dcff08619f8d91607cfc726518b6fa2a9eba42856be181c6d0d9515fd",
|
||||
"sha256:40f4774f5a9d4f5e344f31a32b5096977b5d48560c5592e2f3d2c4374bd543ee",
|
||||
"sha256:4289fc34b2f5316fbb762d75362931e351941fa95fa18789191b33fc4cf9504a",
|
||||
"sha256:470c103ae716238bbe698d67ad020e1db9d9dba34fa5a899b5e21577e6d52ed2",
|
||||
"sha256:4f2c9f67e9821cad2e5f480bc8d83b8742896f1242dba247911072d4fa94c192",
|
||||
"sha256:50a74364d85fd319352182ef59c5c790484a336f6db772c1a9231f1c3ed0cbd7",
|
||||
"sha256:54a2db7b78338edd780e7ef7f9f6c442500fb0d41a5a4ea24fff1c929d5af585",
|
||||
"sha256:5635bd9cb9731e6d4a1132a498dd34f764034a8ce60cef4f5319c0541159392f",
|
||||
"sha256:59c0b02d0a6c384d453fece7566d1c7e6b7bae4fc5874ef2ef46d56776d61c9e",
|
||||
"sha256:5d598b938678ebf3c67377cdd45e09d431369c3b1a5b331058c338e201f12b27",
|
||||
"sha256:5df2768244d19ab7f60546d0c7c63ce1581f7af8b5de3eb3004b9b6fc8a9f84b",
|
||||
"sha256:5ef34d190326c3b1f822a5b7a45f6c4535e2f47ed06fec77d3d799c450b2651e",
|
||||
"sha256:6975a3fac6bc83c4a65c9f9fcab9e47019a11d3d2cf7f3c0d03431bf145a941e",
|
||||
"sha256:6c9a799e985904922a4d207a94eae35c78ebae90e128f0c4e521ce339396be9d",
|
||||
"sha256:70df4e3b545a17496c9b3f41f5115e69a4f2e77e94e1d2a8e1070bc0c38c8a3c",
|
||||
"sha256:7473e861101c9e72452f9bf8acb984947aa1661a7704553a9f6e4baa5ba64415",
|
||||
"sha256:8102eaf27e1e448db915d08afa8b41d6c7ca7a04b7d73af6514df10a3e74bd82",
|
||||
"sha256:87c450779d0914f2861b8526e035c5e6da0a3199d8f1add1a665e1cbc6fc6d02",
|
||||
"sha256:8b7ee99e510d7b66cdb6c593f21c043c248537a32e0bedf02e01e9553a172314",
|
||||
"sha256:91fc98adde3d7881af9b59ed0294046f3806221863722ba7d8d120c575314325",
|
||||
"sha256:94411f22c3985acaec6f83c6df553f2dbe17b698cc7f8ae751ff2237d96b9e3c",
|
||||
"sha256:98d85c6a2bef81588d9227dde12db8a7f47f639f4a17c9ae08e773aa9c697bf3",
|
||||
"sha256:9ad5db27f9cabae298d151c85cf2bad1d359a1b9c686a275df03385758e2f914",
|
||||
"sha256:a0b71b1b8fbf2b96e41c4d990244165e2c9be83d54962a9a1d118fd8657d2045",
|
||||
"sha256:a0f100c8912c114ff53e1202d0078b425bee3649ae34d7b070e9697f93c5d52d",
|
||||
"sha256:a591fe9e525846e4d154205572a029f653ada1a78b93697f3b5a8f1f2bc055b9",
|
||||
"sha256:a5c84c68147988265e60416b57fc83425a78058853509c1b0629c180094904a5",
|
||||
"sha256:a66d3508133af6e8548451b25058d5812812ec3798c886bf38ed24a98216fab2",
|
||||
"sha256:a8c4917bd7ad33e8eb21e9a5bbba979b49d9a97acb3a803092cbc1133e20343c",
|
||||
"sha256:b3bbeb01c2b273cca1e1e0c5df57f12dce9a4dd331b4fa1635b8bec26350bde3",
|
||||
"sha256:cba9d6b9a7d64d4bd46167096fc9d2f835e25d7e4c121fb2ddfc6528fb0413b2",
|
||||
"sha256:cc4d65aeeaa04136a12677d3dd0b1c0c94dc43abac5860ab33cceb42b801c1e8",
|
||||
"sha256:ce4bcc037df4fc5e3d184794f27bdaab018943698f4ca31630bc7f84a7b69c6d",
|
||||
"sha256:cec7d9412a9102bdc577382c3929b337320c4c4c4849f2c5cdd14d7368c5562d",
|
||||
"sha256:d400bfb9a37b1351253cb402671cea7e89bdecc294e8016a707f6d1d8ac934f9",
|
||||
"sha256:d61f4695e6c866a23a21acab0509af1cdfd2c013cf256bbf5b6b5e2695827162",
|
||||
"sha256:db0fbb9c62743ce59a9ff687eb5f4afbe77e5e8403d6697f7446e5f609976f76",
|
||||
"sha256:dd86c085fae2efd48ac91dd7ccffcfc0571387fe1193d33b6394db7ef31fe2a4",
|
||||
"sha256:e00b098126fd45523dd056d2efba6c5a63b71ffe9f2bbe1a4fe1716e1d0c331e",
|
||||
"sha256:e229a521186c75c8ad9490854fd8bbdd9a0c9aa3a524326b55be83b54d4e0ad9",
|
||||
"sha256:e263d77ee3dd201c3a142934a086a4450861778baaeeb45db4591ef65550b0a6",
|
||||
"sha256:ed9cb427ba5504c1dc15ede7d516b84757c3e3d7868ccc85121d9310d27eed0b",
|
||||
"sha256:fa6693661a4c91757f4412306191b6dc88c1703f780c8234035eac011922bc01",
|
||||
"sha256:fcd131dd944808b5bdb38e6f5b53013c5aa4f334c5cad0c72742f6eba4b73db0"
|
||||
],
|
||||
"version": "==1.15.1"
|
||||
},
|
||||
"cryptography": {
|
||||
"hashes": [
|
||||
"sha256:0297ffc478bdd237f5ca3a7dc96fc0d315670bfa099c04dc3a4a2172008a405a",
|
||||
"sha256:10d1f29d6292fc95acb597bacefd5b9e812099d75a6469004fd38ba5471a977f",
|
||||
"sha256:16fa61e7481f4b77ef53991075de29fc5bacb582a1244046d2e8b4bb72ef66d0",
|
||||
"sha256:194044c6b89a2f9f169df475cc167f6157eb9151cc69af8a2a163481d45cc407",
|
||||
"sha256:1db3d807a14931fa317f96435695d9ec386be7b84b618cc61cfa5d08b0ae33d7",
|
||||
"sha256:3261725c0ef84e7592597606f6583385fed2a5ec3909f43bc475ade9729a41d6",
|
||||
"sha256:3b72c360427889b40f36dc214630e688c2fe03e16c162ef0aa41da7ab1455153",
|
||||
"sha256:3e3a2599e640927089f932295a9a247fc40a5bdf69b0484532f530471a382750",
|
||||
"sha256:3fc26e22840b77326a764ceb5f02ca2d342305fba08f002a8c1f139540cdfaad",
|
||||
"sha256:5067ee7f2bce36b11d0e334abcd1ccf8c541fc0bbdaf57cdd511fdee53e879b6",
|
||||
"sha256:52e7bee800ec869b4031093875279f1ff2ed12c1e2f74923e8f49c916afd1d3b",
|
||||
"sha256:64760ba5331e3f1794d0bcaabc0d0c39e8c60bf67d09c93dc0e54189dfd7cfe5",
|
||||
"sha256:765fa194a0f3372d83005ab83ab35d7c5526c4e22951e46059b8ac678b44fa5a",
|
||||
"sha256:79473cf8a5cbc471979bd9378c9f425384980fcf2ab6534b18ed7d0d9843987d",
|
||||
"sha256:896dd3a66959d3a5ddcfc140a53391f69ff1e8f25d93f0e2e7830c6de90ceb9d",
|
||||
"sha256:89ed49784ba88c221756ff4d4755dbc03b3c8d2c5103f6d6b4f83a0fb1e85294",
|
||||
"sha256:ac7e48f7e7261207d750fa7e55eac2d45f720027d5703cd9007e9b37bbb59ac0",
|
||||
"sha256:ad7353f6ddf285aeadfaf79e5a6829110106ff8189391704c1d8801aa0bae45a",
|
||||
"sha256:b0163a849b6f315bf52815e238bc2b2346604413fa7c1601eea84bcddb5fb9ac",
|
||||
"sha256:b6c9b706316d7b5a137c35e14f4103e2115b088c412140fdbd5f87c73284df61",
|
||||
"sha256:c2e5856248a416767322c8668ef1845ad46ee62629266f84a8f007a317141013",
|
||||
"sha256:ca9f6784ea96b55ff41708b92c3f6aeaebde4c560308e5fbbd3173fbc466e94e",
|
||||
"sha256:d1a5bd52d684e49a36582193e0b89ff267704cd4025abefb9e26803adeb3e5fb",
|
||||
"sha256:d3971e2749a723e9084dd507584e2a2761f78ad2c638aa31e80bc7a15c9db4f9",
|
||||
"sha256:d4ef6cc305394ed669d4d9eebf10d3a101059bdcf2669c366ec1d14e4fb227bd",
|
||||
"sha256:d9e69ae01f99abe6ad646947bba8941e896cb3aa805be2597a0400e0764b5818"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==38.0.1"
|
||||
},
|
||||
"dnspython": {
|
||||
"hashes": [
|
||||
"sha256:0f7569a4a6ff151958b64304071d370daa3243d15941a7beedf0c9fe5105603e",
|
||||
"sha256:a851e51367fb93e9e1361732c1d60dab63eff98712e503ea7d92e6eccb109b4f"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.2.1"
|
||||
},
|
||||
"paramiko": {
|
||||
"hashes": [
|
||||
"sha256:003e6bee7c034c21fbb051bf83dc0a9ee4106204dd3c53054c71452cc4ec3938",
|
||||
"sha256:655f25dc8baf763277b933dfcea101d636581df8d6b9774d1fb653426b72c270"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.11.0"
|
||||
},
|
||||
"pycparser": {
|
||||
"hashes": [
|
||||
"sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9",
|
||||
"sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"
|
||||
],
|
||||
"version": "==2.21"
|
||||
},
|
||||
"pynacl": {
|
||||
"hashes": [
|
||||
"sha256:06b8f6fa7f5de8d5d2f7573fe8c863c051225a27b61e6860fd047b1775807858",
|
||||
"sha256:0c84947a22519e013607c9be43706dd42513f9e6ae5d39d3613ca1e142fba44d",
|
||||
"sha256:20f42270d27e1b6a29f54032090b972d97f0a1b0948cc52392041ef7831fee93",
|
||||
"sha256:401002a4aaa07c9414132aaed7f6836ff98f59277a234704ff66878c2ee4a0d1",
|
||||
"sha256:52cb72a79269189d4e0dc537556f4740f7f0a9ec41c1322598799b0bdad4ef92",
|
||||
"sha256:61f642bf2378713e2c2e1de73444a3778e5f0a38be6fee0fe532fe30060282ff",
|
||||
"sha256:8ac7448f09ab85811607bdd21ec2464495ac8b7c66d146bf545b0f08fb9220ba",
|
||||
"sha256:a36d4a9dda1f19ce6e03c9a784a2921a4b726b02e1c736600ca9c22029474394",
|
||||
"sha256:a422368fc821589c228f4c49438a368831cb5bbc0eab5ebe1d7fac9dded6567b",
|
||||
"sha256:e46dae94e34b085175f8abb3b0aaa7da40767865ac82c928eeb9e57e1ea8a543"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==1.5.0"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
|
||||
"sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==1.16.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
from tkinter import W
|
||||
import paramiko, os, dns.resolver
|
||||
|
||||
router_ip = os.getenv("ROUTER_ADDRESS", "192.168.0.1")
|
||||
router_username = os.getenv("ROUTER_USER", "admin")
|
||||
router_password = os.getenv("ROUTER_PASSWORD")
|
||||
interface_name = os.getenv("INTERFACE_NAME")
|
||||
|
||||
auto_vpn_route_comment = "!twitter"
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
# Load SSH host keys.
|
||||
ssh.load_system_host_keys()
|
||||
# Add SSH host key automatically if needed.
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
# Connect to router using username/password authentication.
|
||||
ssh.connect(router_ip,
|
||||
username=router_username,
|
||||
password=router_password,
|
||||
look_for_keys=False )
|
||||
|
||||
def get_ips_for_domain_name(domain_name):
|
||||
resolver = dns.resolver.Resolver()
|
||||
result = resolver.resolve(domain_name, 'A')
|
||||
return [ip.to_text() for ip in result]
|
||||
|
||||
def exec_command(command):
|
||||
# Run command.
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(command)
|
||||
ssh_stdin.close()
|
||||
|
||||
# убираем лишние переносы строки из вывода
|
||||
clean_lines = []
|
||||
for line in ssh_stdout.readlines():
|
||||
clean_lines.append(line.strip())
|
||||
|
||||
return clean_lines
|
||||
|
||||
def get_current_settings():
|
||||
return exec_command("more running-config")
|
||||
|
||||
def get_current_rules():
|
||||
rules = []
|
||||
output = get_current_settings()
|
||||
for line in output:
|
||||
if auto_vpn_route_comment in line:
|
||||
rules.append(line)
|
||||
return rules
|
||||
|
||||
|
||||
def add_vpn_route(ip):
|
||||
if not ip == "127.0.0.1":
|
||||
command = f"ip route {ip} {interface_name} auto {auto_vpn_route_comment}"
|
||||
output = "".join(exec_command(command)).strip()
|
||||
|
||||
return output
|
||||
else:
|
||||
return False
|
||||
|
||||
def delete_vpn_route(ip):
|
||||
command = f"no ip route {ip} {interface_name} {auto_vpn_route_comment}"
|
||||
output = "".join(exec_command(command)).strip()
|
||||
|
||||
return output
|
||||
|
||||
# print("Getting current auto-vpn routes:")
|
||||
# print(get_current_rules())
|
||||
# print()
|
||||
|
||||
# for line in get_current_rules():
|
||||
# ip = line.split(" ")[2]
|
||||
# print(delete_vpn_route(ip))
|
||||
|
||||
with open('ip_lists/facebook.txt') as f:
|
||||
for line in f.readlines():
|
||||
print(line.strip())
|
||||
print(add_vpn_route(line.strip()))
|
||||
|
||||
|
||||
# Close connection.
|
||||
ssh.close()
|
||||
@@ -1,3 +0,0 @@
|
||||
kinozal.tv
|
||||
rutracker.org
|
||||
rpm.grafana.com
|
||||
@@ -1,100 +0,0 @@
|
||||
102.132.100.0/24
|
||||
102.132.101.0/24
|
||||
102.132.96.0/20
|
||||
102.132.96.0/24
|
||||
102.132.99.0/24
|
||||
103.4.96.0/22
|
||||
129.134.0.0/17
|
||||
129.134.25.0/24
|
||||
129.134.26.0/24
|
||||
129.134.27.0/24
|
||||
129.134.28.0/24
|
||||
129.134.29.0/24
|
||||
129.134.30.0/23
|
||||
129.134.30.0/24
|
||||
129.134.31.0/24
|
||||
157.240.0.0/17
|
||||
157.240.10.0/24
|
||||
157.240.11.0/24
|
||||
157.240.12.0/24
|
||||
157.240.13.0/24
|
||||
157.240.14.0/24
|
||||
157.240.15.0/24
|
||||
157.240.17.0/24
|
||||
157.240.18.0/24
|
||||
157.240.19.0/24
|
||||
157.240.192.0/18
|
||||
157.240.194.0/24
|
||||
157.240.195.0/24
|
||||
157.240.196.0/24
|
||||
157.240.197.0/24
|
||||
157.240.199.0/24
|
||||
157.240.200.0/24
|
||||
157.240.20.0/24
|
||||
157.240.201.0/24
|
||||
157.240.2.0/24
|
||||
157.240.203.0/24
|
||||
157.240.204.0/24
|
||||
157.240.205.0/24
|
||||
157.240.206.0/24
|
||||
157.240.209.0/24
|
||||
157.240.210.0/24
|
||||
157.240.21.0/24
|
||||
157.240.211.0/24
|
||||
157.240.212.0/24
|
||||
157.240.213.0/24
|
||||
157.240.214.0/24
|
||||
157.240.215.0/24
|
||||
157.240.216.0/24
|
||||
157.240.217.0/24
|
||||
157.240.218.0/24
|
||||
157.240.220.0/24
|
||||
157.240.22.0/24
|
||||
157.240.221.0/24
|
||||
157.240.222.0/24
|
||||
157.240.223.0/24
|
||||
157.240.225.0/24
|
||||
157.240.226.0/24
|
||||
157.240.229.0/24
|
||||
157.240.231.0/24
|
||||
157.240.232.0/24
|
||||
157.240.233.0/24
|
||||
157.240.234.0/24
|
||||
157.240.235.0/24
|
||||
157.240.236.0/24
|
||||
157.240.238.0/24
|
||||
157.240.240.0/24
|
||||
157.240.24.0/24
|
||||
157.240.241.0/24
|
||||
157.240.243.0/24
|
||||
157.240.245.0/24
|
||||
157.240.247.0/24
|
||||
157.240.25.0/24
|
||||
157.240.26.0/24
|
||||
157.240.27.0/24
|
||||
157.240.28.0/24
|
||||
157.240.30.0/24
|
||||
157.240.3.0/24
|
||||
157.240.6.0/24
|
||||
157.240.7.0/24
|
||||
157.240.8.0/24
|
||||
157.240.9.0/24
|
||||
173.252.64.0/19
|
||||
173.252.88.0/21
|
||||
173.252.96.0/19
|
||||
179.60.192.0/22
|
||||
179.60.192.0/24
|
||||
179.60.193.0/24
|
||||
179.60.194.0/24
|
||||
179.60.195.0/24
|
||||
185.60.216.0/22
|
||||
185.60.216.0/24
|
||||
185.60.217.0/24
|
||||
185.60.218.0/24
|
||||
185.89.218.0/23
|
||||
185.89.218.0/24
|
||||
185.89.219.0/24
|
||||
204.15.20.0/22
|
||||
31.13.24.0/21
|
||||
31.13.64.0/18
|
||||
31.13.64.0/24
|
||||
@@ -1,90 +0,0 @@
|
||||
103.252.112.0/23
|
||||
103.252.114.0/23
|
||||
104.244.40.0/24
|
||||
104.244.41.0/24
|
||||
104.244.42.0/24
|
||||
104.244.44.0/24
|
||||
104.244.45.0/24
|
||||
104.244.46.0/24
|
||||
104.244.47.0/24
|
||||
185.45.5.0/24
|
||||
185.45.6.0/23
|
||||
188.64.224.0/21
|
||||
192.133.76.0/22
|
||||
192.133.76.0/23
|
||||
192.44.69.0/24
|
||||
199.16.156.0/22
|
||||
199.16.156.0/23
|
||||
199.59.148.0/22
|
||||
199.96.56.0/23
|
||||
199.96.56.0/24
|
||||
199.96.57.0/24
|
||||
199.96.58.0/23
|
||||
199.96.60.0/23
|
||||
199.96.60.0/24
|
||||
199.96.61.0/24
|
||||
199.96.62.0/23
|
||||
202.160.128.0/24
|
||||
202.160.129.0/24
|
||||
202.160.130.0/24
|
||||
202.160.131.0/24
|
||||
209.237.192.0/24
|
||||
209.237.193.0/24
|
||||
209.237.194.0/24
|
||||
209.237.195.0/24
|
||||
209.237.196.0/24
|
||||
209.237.197.0/24
|
||||
209.237.198.0/24
|
||||
209.237.199.0/24
|
||||
209.237.200.0/24
|
||||
209.237.201.0/24
|
||||
209.237.203.0/24
|
||||
209.237.205.0/24
|
||||
209.237.206.0/24
|
||||
209.237.208.0/24
|
||||
209.237.209.0/24
|
||||
209.237.210.0/24
|
||||
209.237.211.0/24
|
||||
209.237.212.0/24
|
||||
209.237.213.0/24
|
||||
209.237.214.0/24
|
||||
209.237.215.0/24
|
||||
209.237.216.0/24
|
||||
209.237.217.0/24
|
||||
209.237.218.0/24
|
||||
209.237.219.0/24
|
||||
209.237.220.0/24
|
||||
209.237.221.0/24
|
||||
209.237.222.0/24
|
||||
209.237.223.0/24
|
||||
64.63.0.0/18
|
||||
64.63.32.0/24
|
||||
64.63.33.0/24
|
||||
69.195.160.0/24
|
||||
69.195.162.0/24
|
||||
69.195.163.0/24
|
||||
69.195.164.0/24
|
||||
69.195.165.0/24
|
||||
69.195.166.0/24
|
||||
69.195.168.0/24
|
||||
69.195.169.0/24
|
||||
69.195.171.0/24
|
||||
69.195.172.0/24
|
||||
69.195.174.0/24
|
||||
69.195.175.0/24
|
||||
69.195.176.0/24
|
||||
69.195.177.0/24
|
||||
69.195.178.0/24
|
||||
69.195.179.0/24
|
||||
69.195.180.0/24
|
||||
69.195.181.0/24
|
||||
69.195.182.0/24
|
||||
69.195.183.0/24
|
||||
69.195.184.0/24
|
||||
69.195.185.0/24
|
||||
69.195.186.0/24
|
||||
69.195.187.0/24
|
||||
69.195.188.0/24
|
||||
69.195.189.0/24
|
||||
69.195.190.0/24
|
||||
69.195.191.0/24
|
||||
132
main.py
132
main.py
@@ -1,132 +0,0 @@
|
||||
import paramiko, os, dns.resolver
|
||||
import contextvars
|
||||
import argparse
|
||||
|
||||
router_ip = os.getenv("ROUTER_ADDRESS", "192.168.0.1")
|
||||
router_username = os.getenv("ROUTER_USER", "admin")
|
||||
router_password = os.getenv("ROUTER_PASSWORD")
|
||||
interface_name = os.getenv("INTERFACE_NAME")
|
||||
|
||||
auto_vpn_route_comment = contextvars.ContextVar('auto_vpn_route_comment')
|
||||
ssh_client = contextvars.ContextVar('ssh_client')
|
||||
|
||||
def get_ips_for_domain_name(domain_name):
|
||||
resolver = dns.resolver.Resolver()
|
||||
result = resolver.resolve(domain_name, 'A')
|
||||
return [ip.to_text() for ip in result]
|
||||
|
||||
def exec_command(command):
|
||||
# Run command.
|
||||
ssh_stdin, ssh_stdout, ssh_stderr = ssh_client.get().exec_command(command)
|
||||
ssh_stdin.close()
|
||||
|
||||
# убираем лишние переносы строки из вывода
|
||||
clean_lines = [line.strip() for line in ssh_stdout.readlines()]
|
||||
|
||||
return clean_lines
|
||||
|
||||
def get_current_settings():
|
||||
return exec_command("more running-config")
|
||||
|
||||
def get_current_rules():
|
||||
output = get_current_settings()
|
||||
|
||||
return [rule for rule in output if auto_vpn_route_comment.get() in rule]
|
||||
|
||||
def get_all_rules_by_interface():
|
||||
output = get_current_settings()
|
||||
|
||||
return [rule for rule in output if interface_name in rule]
|
||||
|
||||
def add_vpn_route(ip):
|
||||
if not ip == "127.0.0.1":
|
||||
command = f"ip route {ip} {interface_name} auto {auto_vpn_route_comment.get()}"
|
||||
output = "".join(exec_command(command)).strip()
|
||||
|
||||
return output
|
||||
else:
|
||||
return False
|
||||
|
||||
def delete_vpn_route(ip):
|
||||
command = f"no ip route {ip} {interface_name} {auto_vpn_route_comment.get()}"
|
||||
output = "".join(exec_command(command)).strip()
|
||||
|
||||
return output
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog = 'Keenetic auto vpn',
|
||||
description = '',
|
||||
epilog = '')
|
||||
|
||||
parser.add_argument('-i', '--ip-list')
|
||||
parser.add_argument('-d', '--drop',
|
||||
help='Whether drop or not old rules by that tag',
|
||||
action='store_true')
|
||||
parser.add_argument('-D', '--drop-all',
|
||||
help='Drops ALL current custom routes to given interface')
|
||||
args = parser.parse_args()
|
||||
print(type(args.ip_list))
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
# Load SSH host keys.
|
||||
ssh.load_system_host_keys()
|
||||
# Add SSH host key automatically if needed.
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
# Connect to router using username/password authentication.
|
||||
ssh.connect(router_ip,
|
||||
username=router_username,
|
||||
password=router_password,
|
||||
look_for_keys=False )
|
||||
|
||||
ssh_client.set(ssh)
|
||||
|
||||
|
||||
print(get_all_rules_by_interface())
|
||||
|
||||
if args.drop:
|
||||
for line in get_current_rules():
|
||||
ip = line.split(" ")[2]
|
||||
print(delete_vpn_route(ip))
|
||||
|
||||
if args.ip_list:
|
||||
print("processing ips list")
|
||||
if os.path.exists(args.ip_list):
|
||||
print(f"using file: {args.ip_list}")
|
||||
with open(args.ip_list) as f:
|
||||
auto_vpn_route_comment.set(f"!{os.path.basename(args.ip_list)}")
|
||||
for line in f.readlines():
|
||||
print(line.strip())
|
||||
print(add_vpn_route(line.strip()))
|
||||
print(os.path.basename(args.ip_list))
|
||||
else:
|
||||
print("ip list file not found")
|
||||
else:
|
||||
print("processing domains list")
|
||||
if os.path.exists('domains.txt'):
|
||||
with open('domains.txt') as f:
|
||||
auto_vpn_route_comment.set("!auto-vpn")
|
||||
for line in f.readlines():
|
||||
print(line.strip() + ":")
|
||||
try:
|
||||
ips_list = get_ips_for_domain_name(line.strip())
|
||||
except dns.resolver.NoAnswer:
|
||||
pass
|
||||
print(ips_list)
|
||||
for ip in ips_list:
|
||||
print(add_vpn_route(ip))
|
||||
else:
|
||||
print("Please, create 'domains.txt' file filled with list of domain names to resolve")
|
||||
|
||||
# print("Getting current auto-vpn routes:")
|
||||
# print(get_current_rules())
|
||||
# print()
|
||||
|
||||
|
||||
# Close connection.
|
||||
ssh.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
14
scripts/opt_bin/apply_unblock_rules.sh
Normal file
14
scripts/opt_bin/apply_unblock_rules.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/opt/bin/sh
|
||||
|
||||
set -o xtrace
|
||||
export PATH=/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
export HOME=/opt/root
|
||||
|
||||
ssh -i /opt/root/.ssg/id_dropbear dns@fb.megavenik.ru "dig a api.themoviedb.org +short" < /dev/zero | awk '/^[0-9]/{print "address=/api.themoviedb.org/"$1}' > /opt/etc/dnsmasq.themoviedb.conf
|
||||
echo "address=/api.themoviedb.org/::" >> /opt/etc/dnsmasq.themoviedb.conf
|
||||
ssh -i /opt/root/.ssh/id_dropbear dns@fb.megavenik.ru "dig a image.tmdb.org +short" < /dev/zero | awk '/^[0-9]/{print "address=/image.tmdb.org/"$1}' >> /opt/etc/dnsmasq.themoviedb.conf
|
||||
echo "address=/image.tmdb.org/::" >> /opt/etc/dnsmasq.themoviedb.conf
|
||||
/opt/bin/unblock_dnsmasq.sh
|
||||
/opt/etc/init.d/S56dnsmasq restart
|
||||
/opt/bin/unblock_ipset.sh
|
||||
|
||||
14
scripts/opt_bin/unblock_dnsmasq.sh
Normal file
14
scripts/opt_bin/unblock_dnsmasq.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
cat /dev/null > /opt/etc/unblock.dnsmasq
|
||||
|
||||
while read line || [ -n "$line" ]; do
|
||||
|
||||
[ -z "$line" ] && continue
|
||||
[ "${line:0:1}" = "#" ] && continue
|
||||
|
||||
echo $line | grep -Eq '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' && continue
|
||||
|
||||
echo "ipset=/$line/unblock" >> /opt/etc/unblock.dnsmasq
|
||||
|
||||
done < /opt/etc/unblock.txt
|
||||
33
scripts/opt_bin/unblock_ipset.sh
Normal file
33
scripts/opt_bin/unblock_ipset.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
until ADDRS=$(dig +short google.com @localhost) && [ -n "$ADDRS" ] > /dev/null 2>&1; do sleep 5; done
|
||||
|
||||
while read line || [ -n "$line" ]; do
|
||||
|
||||
[ -z "$line" ] && continue
|
||||
[ "${line:0:1}" = "#" ] && continue
|
||||
|
||||
cidr=$(echo $line | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}')
|
||||
|
||||
if [ ! -z "$cidr" ]; then
|
||||
ipset -exist add unblock $cidr
|
||||
continue
|
||||
fi
|
||||
|
||||
range=$(echo $line | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}-[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
|
||||
|
||||
if [ ! -z "$range" ]; then
|
||||
ipset -exist add unblock $range
|
||||
continue
|
||||
fi
|
||||
|
||||
addr=$(echo $line | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
|
||||
|
||||
if [ ! -z "$addr" ]; then
|
||||
ipset -exist add unblock $addr
|
||||
continue
|
||||
fi
|
||||
|
||||
dig +short $line @localhost | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '{system("ipset -exist add unblock "$1)}'
|
||||
|
||||
done < /opt/etc/unblock.txt
|
||||
171
scripts/opt_etc/unblock.txt
Normal file
171
scripts/opt_etc/unblock.txt
Normal file
@@ -0,0 +1,171 @@
|
||||
###Торрент-трекеры
|
||||
rutracker.org
|
||||
rutracker.cc
|
||||
bt4.t-ru.org
|
||||
rutor.info
|
||||
rutor.is
|
||||
mega-tor.org
|
||||
kinozal.tv
|
||||
nnm-club.me
|
||||
nnm-club.ws
|
||||
tfile.me
|
||||
tfile-home.org
|
||||
tfile1.cc
|
||||
megatfile.cc
|
||||
megapeer.org
|
||||
megapeer.ru
|
||||
tapochek.net
|
||||
tparser.org
|
||||
tparser.me
|
||||
rustorka.com
|
||||
uniongang.tv
|
||||
fast-torrent.ru
|
||||
1337x.to
|
||||
1337x.ws
|
||||
1337x.so
|
||||
1337x.st
|
||||
1337x.se
|
||||
1337x.eu
|
||||
nnm-club.to
|
||||
nnmclub.to
|
||||
gofile.io
|
||||
|
||||
|
||||
###Каталоги медиаконтента для программ
|
||||
rezka.ag
|
||||
hdrezka.ag
|
||||
hdrezka.me
|
||||
filmix.co
|
||||
filmix.cc
|
||||
seasonvar.ru
|
||||
api.themoviedb.org
|
||||
www.themoviedb.org
|
||||
image.tmdb.org
|
||||
cdn.syncfusion.com
|
||||
help.syncfusion.com
|
||||
radarr.video
|
||||
image.tmdb.org
|
||||
prowlarr.com
|
||||
prowlarr.servarr.com
|
||||
#kinopub
|
||||
6786.dpr.ovh
|
||||
kino.pub
|
||||
mos-gorsud.org
|
||||
xszt.sfm.ovh
|
||||
cdntogo.net
|
||||
cdn.service-kp.com
|
||||
api.srvkp.com
|
||||
3ds.customfw.xyz
|
||||
|
||||
www.gamedev.tv
|
||||
api.gamedev.tv
|
||||
getoutline.com
|
||||
mattermost.com
|
||||
mattermost.uservoice.com
|
||||
cdn.srvkp.com
|
||||
play.google.com
|
||||
quora.com
|
||||
www.quora.com
|
||||
www.coursera.org
|
||||
|
||||
###Книги
|
||||
lib.rus.ec
|
||||
flibusta.is
|
||||
flibs.me
|
||||
flisland.net
|
||||
flibusta.site
|
||||
|
||||
###Сайтики
|
||||
medium.com
|
||||
hashicorp.com
|
||||
drawio.com
|
||||
all3dp.com
|
||||
paperpaper.io
|
||||
|
||||
## onshape.com
|
||||
cad.onshape.com
|
||||
forum.onshape.com
|
||||
cad-euw1.onshape.com
|
||||
www.zuora.com
|
||||
|
||||
###Порно
|
||||
fakku.net
|
||||
pornhub.com
|
||||
ei.phncdn.com
|
||||
ev-h.phncdn.com
|
||||
ev.phncdn.com
|
||||
pornolab.net
|
||||
plab.site
|
||||
|
||||
###Социалки
|
||||
facebook.com
|
||||
instagram.com
|
||||
cdninstagram.com
|
||||
cdnfacebook.com
|
||||
facebook.net
|
||||
i.ytimg.com
|
||||
ads-twitter.com
|
||||
mobile.twitter.com
|
||||
static.ads-twitter.com
|
||||
twitter.com
|
||||
api.twitter.com
|
||||
t.co
|
||||
twimg.com
|
||||
abs.twimg.com
|
||||
104.244.40.0/21
|
||||
147.75.208.0/20
|
||||
185.89.216.0/22
|
||||
31.13.24.0/21
|
||||
31.13.64.0/18
|
||||
45.64.40.0/22
|
||||
66.220.144.0/20
|
||||
69.63.176.0/20
|
||||
69.171.224.0/19
|
||||
74.119.76.0/22
|
||||
102.132.96.0/20
|
||||
103.4.96.0/22
|
||||
129.134.0.0/16
|
||||
157.240.0.0/16
|
||||
163.70.128.0/17
|
||||
163.77.128.0/17
|
||||
173.252.64.0/18
|
||||
179.60.192.0/22
|
||||
185.60.216.0/22
|
||||
204.15.20.0/22
|
||||
93.184.220.0/22
|
||||
192.229.128.0/17
|
||||
69.195.160.0/19
|
||||
|
||||
###Телеграм
|
||||
#telegram.org
|
||||
#tdesktop.com
|
||||
#tdesktop.org
|
||||
#tdesktop.info
|
||||
#tdesktop.net
|
||||
#telesco.pe
|
||||
#telegram.dog
|
||||
#telegram.me
|
||||
#t.me
|
||||
#telegra.ph
|
||||
#web.telegram.org
|
||||
#desktop.telegram.org
|
||||
#updates.tdesktop.com
|
||||
#venus.web.telegram.org
|
||||
#flora.web.telegram.org
|
||||
#vesta.web.telegram.org
|
||||
#pluto.web.telegram.org
|
||||
#aurora.web.telegram.org
|
||||
#149.154.160.0/20
|
||||
#91.108.4.0/22
|
||||
#91.108.8.0/22
|
||||
#91.108.12.0/22
|
||||
#91.108.16.0/22
|
||||
#91.108.56.0/22
|
||||
#109.239.140.0/24
|
||||
#67.198.55.0/24
|
||||
|
||||
###Разное
|
||||
7-zip.org
|
||||
edem.tv
|
||||
4pna.com
|
||||
2019.vote
|
||||
Reference in New Issue
Block a user