逻辑:中国大陆路由表正常走出口,香港流量走默认路由
代码语言:javascript复制import os
import time
def time_out(): #时间区分文件名
txt_name =time.strftime("%Y-%m-%d:%H:%M:%S", time.localtime())
#print(txt_name)
return str(txt_name) '.txt'
def wget_os(url,txt_name): #执行wget操作 从github上拉取大陆路由表
code = os.system("wget " url " -O " txt_name)
return code #返回是否操作成功
gateway=input('输入网关ip:')
rsc_name=input('导出文件名:')
txt_name=time_out()
a = wget_os('https://raw.githubusercontent.com/17mon/china_ip_list/master/china_ip_list.txt',txt_name)
if a == 0:
f = open(txt_name,'r')
num = 0
for lines in f.readlines():
lines=lines.strip('n')
num = num 1
#print('/ip route add dst-address=' lines ' gateway=' gateway ' check-gateway=ping')
os.system('echo "/ip route add dst-address=' lines ' gateway=' gateway ' check-gateway=ping" >> ' rsc_name)
print('新建成功,一共' str(num) '条')
else:
print('wget失败,检查联网')
在ROS中导入rsc文件即可