Skip to content

Instantly share code, notes, and snippets.

@Undifinedu
Created June 7, 2020 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Undifinedu/8d3a79f6d1cd44e3aedfdda4ad55e0f1 to your computer and use it in GitHub Desktop.
Save Undifinedu/8d3a79f6d1cd44e3aedfdda4ad55e0f1 to your computer and use it in GitHub Desktop.
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