separate temp script for adding ip ranges from predefined list
This commit is contained in:
82
add_from_list.py
Normal file
82
add_from_list.py
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
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/twitter.txt') as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
print(line.strip())
|
||||||
|
print(add_vpn_route(line.strip()))
|
||||||
|
|
||||||
|
|
||||||
|
# Close connection.
|
||||||
|
ssh.close()
|
||||||
18
domains.txt
18
domains.txt
@@ -1,18 +1,2 @@
|
|||||||
kinozal.tv
|
kinozal.tv
|
||||||
api.themoviedb.org
|
rutracker.org
|
||||||
rutracker.org
|
|
||||||
|
|
||||||
ads-twitter.com
|
|
||||||
mobile.twitter.com
|
|
||||||
periscope.tv
|
|
||||||
pscp.tv
|
|
||||||
t.co
|
|
||||||
tweetdeck.com
|
|
||||||
twimg.com
|
|
||||||
twitpic.com
|
|
||||||
twitter.co
|
|
||||||
twitter.com
|
|
||||||
twitterinc.com
|
|
||||||
twitteroauth.com
|
|
||||||
twitterstat.us
|
|
||||||
twttr.com
|
|
||||||
90
ip_lists/twitter.txt
Normal file
90
ip_lists/twitter.txt
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
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
|
||||||
Reference in New Issue
Block a user