-
Notifications
You must be signed in to change notification settings - Fork 0
/
filternet.py
57 lines (48 loc) · 2.09 KB
/
filternet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import socket
from sys import platform
from os import popen
distinct_ips = []
domains_list = ['list-of-domains.com']
def linux():
# Find default gateway
default_gw = popen("ip r | grep default | cut -d ' ' -f 3").read().strip()
# Find default ethernet device
default_eth = popen("ip -4 route ls | grep default | cut -d ' ' -f 5").read().strip()
with open('linux.sh', 'w') as file:
file.write(f'''ip route add "YOUR_STATIC_IPs" via {default_gw} dev {default_eth}
''')
for domain in domains_list:
socket_info = socket.getaddrinfo(domain, 0)
for result in socket_info:
ns_ip = result[4][0]
if distinct_ips.count(ns_ip) == 0:
distinct_ips.append(ns_ip)
file.write(f'ip route add {ns_ip} via {default_gw} dev {default_eth}\n')
popen('bash ./linux.sh') # You may comment if don't want to run it
def windows():
with open('windows.cmd', 'w') as file:
file.write('''@echo off
set "ip="
for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do if not defined ip set ip=%%~a
set "command=route add -p"
::set "delete=route delete -p"
::%command% 1.1.1.1 %ip%
::%delete% 1.1.1.1 %ip%
:: in-line comment: %= COMMENT =%
REM remove this line and add your server's static ips if having no domain names
''')
for domain in domains_list:
socket_info = socket.getaddrinfo(domain, 0)
for result in socket_info:
ns_ip = result[4][0]
if distinct_ips.count(ns_ip) == 0:
distinct_ips.append(ns_ip)
file.write(f'echo adding ip {ns_ip} for {domain}\n%command% {ns_ip} %ip%\n')
file.write('\npause')
popen('powershell.exe "Start-Process windows.cmd -verb runAs"') # You may comment if don't want to run it
if platform == "linux" or platform == "linux2":
linux()
elif platform == "darwin":
print('Mac OS, no plans yet:(')
elif platform == "win32":
windows()