Created
June 7, 2020 07:21
-
-
Save Undifinedu/8d3a79f6d1cd44e3aedfdda4ad55e0f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import socket | |
gw = input('输入默认网关:') | |
mask = '255.255.255.0' | |
ip_list = [] | |
domainfile = 'domain.txt' | |
with open(domainfile) as file: | |
domain_list = file.readlines() | |
for domain in domain_list: | |
domain = domain.strip('\n') | |
try: | |
dnsquery = socket.getaddrinfo(domain,None) | |
for i in range(len(dnsquery)): | |
ip_list.append(dnsquery[i][4][0]) | |
except socket.gaierror: | |
continue | |
for destinate_ip in ip_list: | |
print('adding route for :', destinate_ip) | |
os.system('route add %s mask %s %s -p'%(destinate_ip, mask, gw)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment