ROS-大陆路由表rsc脚本生成

时间:2022-07-25
本文章向大家介绍ROS-大陆路由表rsc脚本生成,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

逻辑:中国大陆路由表正常走出口,香港流量走默认路由

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文件即可