GAP自动配置规则脚本

Zss 发表于:

之前出差去中车配置gap的规则,要求一定要使用代理来配置,而且规则也挺多的,所以导致花了很多时间来配置,

眼睛都看花了,而且还怕配置错了,眼花,毕竟看久了,所以回来之后写一个从表格中读取数据来自动配置的脚本,只有模拟登录设备成功了,不知道可能设备型号不一样模拟登录失败了,没法自动拿到cookie,所以手动拿一下cookie写到表格中,这样子添加规则快了很多,只需要整理好表格,对应的方向和端口等

#coding:utf-8
import xlrd,requests,re,os,base64
requests.packages.urllib3.disable_warnings()

class Auto_Rule():
    def __init__(self):
        # (x,y) x:为列,y为行
        # (x,0):源ip
        # (x,2):代理方向
        # (x,3):网闸代理侧ip
        # (x,4):代理端口
        # (x,6):网闸目的侧ip
        # (x,7):目的端ip
        # (x,8):协议
        # (x,9):目的端口
        # (0,12):设备ip
        # (0,14):设备cookie
        print '-----------------------------------------'
        print '               规则配置脚本               '
        print '-----------------------------------------'
        print '     1.首次打开会生成config.xlsx文件    '
        print ' 2.配置正确的config.xlsx,文件内容位置请勿修改'
        print '     3.需要配置正确的Cookie来保证登录'
        print '     4.保证当前PC能与GAP正常通信'
        print '-----------------------------------------'

        data = 'UEsDBBQABgAIAAAAIQCnlfmZhAEAABQGAAATAN0BW0NvbnRlbnRfVHlwZXNdLnhtbCCi2QEooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAjAAAAAAAAAAAAAAAAAK0UAAB4bC93b3Jrc2hlZXRzL19yZWxzL3NoZWV0My54bWwucmVsc1BLAQItABQABgAIAAAAIQBiztRDZQEAAEgCAAAYAAAAAAAAAAAAAAAAALAVAAB4bC93b3Jrc2hlZXRzL3NoZWV0My54bWxQSwECLQAUAAYACAAAACEANBeaDkoFAABnFQAAGAAAAAAAAAAAAAAAAABLFwAAeGwvd29ya3NoZWV0cy9zaGVldDEueG1sUEsBAi0AFAAGAAgAAAAhAEbqxBNUBAAA3A0AABQAAAAAAAAAAAAAAAAAyxwAAHhsL3NoYXJlZFN0cmluZ3MueG1sUEsBAi0AFAAGAAgAAAAhAD29dXMxAgAAcAUAAA0AAAAAAAAAAAAAAAAAUSEAAHhsL3N0eWxlcy54bWxQSwECLQAUAAYACAAAACEABcuMSkcAAABsAQAAJwAAAAAAAAAAAAAAAACtIwAAeGwvcHJpbnRlclNldHRpbmdzL3ByaW50ZXJTZXR0aW5nczIuYmluUEsBAi0AFAAGAAgAAAAhAF3woRmqAAAAEAQAACcAAAAAAAAAAAAAAAAAOSQAAHhsL3ByaW50ZXJTZXR0aW5ncy9wcmludGVyU2V0dGluZ3MxLmJpblBLAQItABQABgAIAAAAIQAFy4xKRwAAAGwBAAAnAAAAAAAAAAAAAAAAACglAAB4bC9wcmludGVyU2V0dGluZ3MvcHJpbnRlclNldHRpbmdzMy5iaW5QSwECLQAUAAYACAAAACEAWBiiUkIBAABRAgAAEQAAAAAAAAAAAAAAAAC0JQAAZG9jUHJvcHMvY29yZS54bWxQSwECLQAUAAYACAAAACEASDwdNqMBAABGAwAAEAAAAAAAAAAAAAAAAAAtKAAAZG9jUHJvcHMvYXBwLnhtbFBLBQYAAAAAEgASAP4EAAAGKwAAAAA='
        if not os.path.exists('config.xlsx'):
            with open('config.xlsx','wb+') as f:
                f.write(base64.b64decode(data))
        raw_input('请配置完当前路径下的config.xlsx,回车继续运行!!!')
        self.data = xlrd.open_workbook('config.xlsx', 'rb')
        self.table = self.data.sheets()[0]
        self.nrows = self.table.nrows
        self.ncols = self.table.ncols
        self.number = 3

    def return_cookie(self):
        return self.table.cell(0, 14).value

    def return_dut_ip(self):
        return self.table.cell(0, 12).value

    def return_obj(self):
        #返回(ip,掩码)
        obj_list = []
        for i in range(1,self.nrows):
            src_info = ((self.table.cell(i, 0).value).split('/')[0],(self.table.cell(i, 0).value).split('/')[1])
            dst_info = ((self.table.cell(i, 7).value).split('/')[0],(self.table.cell(i, 7).value).split('/')[1])
            if src_info not in obj_list:
                obj_list.append(src_info)
            if dst_info not in obj_list:
                obj_list.append(dst_info)
        return obj_list

    def retrun_app(self):
        #返回(名字,代理端口,协议,目的端口)
        app_list = []
        for i in range(1,self.nrows):
            if '-' not in str(self.table.cell(i, 9).value) and '-' not in str(self.table.cell(i, 4).value):
                port_info = (str(self.table.cell(i, 8).value).upper()+'_'+str(int(self.table.cell(i, 4).value))+'-->'+str(int(self.table.cell(i, 9).value)),int(self.table.cell(i, 4).value),str(self.table.cell(i, 8).value).upper(),int(self.table.cell(i, 9).value))
            else:
                port_info = (str(self.table.cell(i, 8).value).upper()+'_'+str(self.table.cell(i, 4).value)+'-->'+str(self.table.cell(i, 9).value),self.table.cell(i, 4).value,str(self.table.cell(i, 8).value).upper(),self.table.cell(i, 9).value)
            if port_info not in app_list:
                app_list.append(port_info)
        return app_list

    def retrun_aisle(self):
        #正确的接口对应的数值(名字,方向(1:e-i,0:i-e),int接口数值sdev,ext接口数值ddev)
        headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Content-Length':'61',
'Cache-Control':'max-age=0',
'Origin':'https://%s'%self.return_dut_ip(),
'Upgrade-Insecure-Requests':'1',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/secway/new_secway'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
         'Cookie':self.return_cookie()}
        data = {'name':'test-aisle','area':'1','ddev':'7','sdev':'6','desc':'','set':'提交'}
        requests.post(url='https://%s/secway/add_secway'%self.return_dut_ip(),headers=headers,data=data,verify=False,allow_redirects=False)

        headers1 = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Upgrade-Insecure-Requests':'1',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/leftframe'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie': self.return_cookie()}
        rsp = requests.get(url='https://%s/secway'%self.return_dut_ip(),headers=headers1,verify=False,allow_redirects=False).text
        aisle_info = re.findall('test-aisle.*>INT(\d).*EXT(\d)',rsp,flags=re.DOTALL)
        try:
            requests.get(url='https://192.168.1.254/secway/delete/test-aisle', headers=headers, verify=False,
                     allow_redirects=False,timeout=1)
        except:pass
        try:
            if 6-int(aisle_info[0][0]) == 7-int(aisle_info[0][1]):
                self.number = 6-int(aisle_info[0][0])
            aisle_info = []
            try:
                for i in range(1,self.nrows):
                    t = self.table.cell(i, 2).value
                    index = i
            except:pass
            for i in range(1,self.nrows):
                if 'i' in self.table.cell(i, 2).value.split('-')[0]:
                    fangxiang = '0'
                else:fangxiang = '1'
                INT = int(re.findall('(\d).{2}(\d)',self.table.cell(i, 2).value)[0][0])+self.number
                EXT = int(re.findall('(\d).{2}(\d)',self.table.cell(i, 2).value)[0][1])+self.number
                info = (self.table.cell(i, 2).value,fangxiang,INT,EXT)
                if info not in aisle_info:
                    aisle_info.append(info)
            return aisle_info
        except Exception as e:
            raw_input('cookie已失效,请填入新cookie!!!')
            exit()

    def retrun_rule(self):
        #返回(规则名,通道名,源对象,目的对象,应用名)
        rule_list = []
        for i in range(1, self.nrows):
            if '-' not in str(self.table.cell(i, 9).value) and '-' not in str(self.table.cell(i, 4).value):
                port_info = str(self.table.cell(i, 8).value).upper()+'_'+str(int(self.table.cell(i, 4).value))+'-->'+str(int(self.table.cell(i, 9).value))
            else:
                port_info = str(self.table.cell(i, 8).value).upper()+'_'+str(self.table.cell(i, 4).value)+'-->'+str(self.table.cell(i, 9).value)
            src_obj = (self.table.cell(i, 0).value).split('/')[0]
            dst_obj = (self.table.cell(i, 7).value).split('/')[0]
            aisle_name = self.table.cell(i, 2).value
            rule_name = 'Rule%d__%s'%(i,port_info)
            if (rule_name,aisle_name,src_obj,dst_obj,port_info) not in rule_list:
                rule_list.append((rule_name,aisle_name,src_obj,dst_obj,port_info))
        return rule_list

    def retrun_int_proxy(self):
        #返回(网闸代理ip,代理协议名,目的ip)
        in_proxy_list = []
        for i in range(1, self.nrows):
            if (self.table.cell(i, 2).value)[0] == 'i' or (self.table.cell(i, 2).value)[0] == 'I':
                gap_in_ip = (self.table.cell(i, 3).value).split('/')[0]
                dst_ip = (self.table.cell(i, 7).value).split('/')[0]
                if '-' not in str(self.table.cell(i, 9).value) and '-' not in str(self.table.cell(i, 4).value):
                    port_info = str(self.table.cell(i, 8).value).upper() + '_' + str(
                        int(self.table.cell(i, 4).value)) + '-->' + str(int(self.table.cell(i, 9).value))
                else:
                    port_info = str(self.table.cell(i, 8).value).upper() + '_' + str(
                        self.table.cell(i, 4).value) + '-->' + str(self.table.cell(i, 9).value)
                in_proxy_list.append((gap_in_ip,port_info,dst_ip))
        return in_proxy_list

    def retrun_ext_proxy(self):
        # 返回(网闸代理ip,代理协议名,目的ip)
        ext_proxy_list = []
        for i in range(1, self.nrows):
            if (self.table.cell(i, 2).value)[0] == 'e' or (self.table.cell(i, 2).value)[0] == 'E':
                gap_in_ip = (self.table.cell(i, 3).value).split('/')[0]
                dst_ip = (self.table.cell(i, 7).value).split('/')[0]
                if '-' not in str(self.table.cell(i, 9).value) and '-' not in str(self.table.cell(i, 4).value):
                    port_info = str(self.table.cell(i, 8).value).upper() + '_' + str(
                        int(self.table.cell(i, 4).value)) + '-->' + str(int(self.table.cell(i, 9).value))
                else:
                    port_info = str(self.table.cell(i, 8).value).upper() + '_' + str(
                        self.table.cell(i, 4).value) + '-->' + str(self.table.cell(i, 9).value)
                ext_proxy_list.append((gap_in_ip, port_info, dst_ip))
        return ext_proxy_list

    def retrun_int_interface(self):
        # 返回(接口id,内网接口名,接口ip,接口掩码)
        int_face_ip = []
        for i in range(1, self.nrows):
            if (self.table.cell(i, 2).value)[0] == 'i' or (self.table.cell(i, 2).value)[0] == 'I':
                int_name = 'INT' + re.findall('.*(\d)',self.table.cell(i, 2).value)[0]
                int_id = str(int(re.findall('.*(\d)',self.table.cell(i, 2).value)[0])+self.number)
                ip,mask = self.table.cell(i, 3).value.split('/')[0],self.table.cell(i, 3).value.split('/')[1]
            else:
                int_name = 'INT' + re.findall('-.*(\d)', self.table.cell(i, 2).value)[0]
                int_id = str(int(re.findall('-.*(\d)', self.table.cell(i, 2).value)[0]) + self.number)
                ip, mask = self.table.cell(i, 6).value.split('/')[0], self.table.cell(i, 6).value.split('/')[1]
            if (int_id,int_name,ip,mask) not in int_face_ip:
                int_face_ip.append((int_id,int_name,ip,mask))
        return int_face_ip

    def retrun_ext_interface(self):
        # 返回(接口id,内网接口名,接口ip,接口掩码)
        ext_face_ip = []
        for i in range(1, self.nrows):
            if (self.table.cell(i, 2).value)[0] == 'e' or (self.table.cell(i, 2).value)[0] == 'E':
                ext_name = 'EXT' + re.findall('.*(\d)',self.table.cell(i, 2).value)[0]
                ext_id = str(int(re.findall('.*(\d)',self.table.cell(i, 2).value)[0])+self.number)
                ip,mask = self.table.cell(i, 3).value.split('/')[0],self.table.cell(i, 3).value.split('/')[1]
            else:
                ext_name = 'EXT' + re.findall('-.*(\d)', self.table.cell(i, 2).value)[0]
                ext_id = str(int(re.findall('-.*(\d)', self.table.cell(i, 2).value)[0]) + self.number)
                ip, mask = self.table.cell(i, 6).value.split('/')[0], self.table.cell(i, 6).value.split('/')[1]
            if (ext_id,ext_name,ip,mask) not in ext_face_ip:
                ext_face_ip.append((ext_id,ext_name,ip,mask))
        return ext_face_ip

    def post_aisle(self,info):
        headers = {'Host': self.return_dut_ip(),
                   'Connection': 'keep-alive',
                   'Content-Length': '61',
                   'Cache-Control': 'max-age=0',
                   'Origin': 'https://%s' % self.return_dut_ip(),
                   'Upgrade-Insecure-Requests': '1',
                   'Content-Type': 'application/x-www-form-urlencoded',
                   'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
                   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                   'Referer': 'https://%s/secway/new_secway' % self.return_dut_ip(),
                   'Accept-Encoding': 'gzip, deflate, br',
                   'Accept-Language': 'zh-CN,zh;q=0.9',
                   'Cookie': self.return_cookie()}
        data = {'name': info[0], 'area': info[1], 'ddev': info[3], 'sdev': info[2], 'desc': '', 'set': '提交'}
        requests.post(url='https://%s/secway/add_secway' % self.return_dut_ip(), headers=headers, data=data,verify=False)

    def post_obj(self,info):
        headers = {'Host':self.return_dut_ip(),
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Accept-Encoding':'gzip, deflate',
'Referer':'https://%s/objs/new_obj'%self.return_dut_ip(),
'Content-Type':'application/x-www-form-urlencoded',
'Connection':'close',
'Cookie': self.return_cookie()}
        if ':' not in info[0]:
            obj_data = {'name':info[0],'iptype':'0','ip':info[0],'mask':info[1],'mac':'00:00:00:00:00:00','desc':'','set':'提交'}
        else:obj_data = {'name':info[0],'iptype':'1','ip':info[0],'mask':info[1],'mac':'00:00:00:00:00:00','desc':'','set':'提交'}

        requests.post(url='https://%s/objs/add_obj'%self.return_dut_ip(),headers=headers,data=obj_data,verify=False)

    def post_app(self,info):
        headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Content-Length':'185',
'Cache-Control':'max-age=0',
'Origin':'https://%s'%self.return_dut_ip(),
'Upgrade-Insecure-Requests':'1',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/apps/new_app'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie': self.return_cookie()}
        url = 'https://%s/apps/add_app'%self.return_dut_ip()
        app_data = {'name':info[0],'protocol':info[2],'asservice':'NULL_TCP','asservice_udp':'NULL_UDP','asservice_icmp':'PING','asservice_icmpv6':'PING6','sport':'1-65535','dport':info[3],'tport':info[1],'action':'1','desc':'','cklog':'1','set':'提交'}
        requests.post(url=url,headers=headers,data=app_data,verify=False)

    def post_time(self):
        headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Content-Length':'202',
'Cache-Control':'max-age=0',
'Origin':'https://%s'%self.return_dut_ip(),
'Upgrade-Insecure-Requests':'1',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/times/new_time'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie': self.return_cookie()}
        url = 'https://%s/times/add_time'%self.return_dut_ip()
        data = ('name', 'all-time'), ('starttime', '00:00:00'), ('endtime', '23:59:59'), ('timetype', '0'), ('desc', ''), ('startdate', ''), ('enddate', ''), ('set', '提交'), ('weekdays[]', '1'), ('weekdays[]', '2'), ('weekdays[]', '3'), ('weekdays[]', '4'), ('weekdays[]', '5')
        requests.post(url=url,headers=headers,data=data,verify=False)

    def post_rule(self,info):
        headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Origin':'https://%s'%self.return_dut_ip(),
'Upgrade-Insecure-Requests':'1',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/rules/new_rule'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie': self.return_cookie()}
        url = 'https://%s/rules/add_rule'%self.return_dut_ip()
        rule_data = {'name':info[0],'secway':info[1],'srcobjs':info[2],'destobjs':info[3],'app':info[4],'timemode':'all-time','occurs':'0','action':'1','desc':'','set':'提交'}
        requests.post(url=url,headers=headers,data=rule_data,verify=False)

    def post_int_ip(self,info):
        headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Origin':'https://%s'%self.return_dut_ip(),
'Upgrade-Insecure-Requests':'1',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/network/in_ipaddr/%s/%s'%(self.return_dut_ip(),info[0],info[1]),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie': self.return_cookie()}
        url = 'https://%s/network/addip_innet'%self.return_dut_ip()
        if ':' not in info[2]:
            int_data = {'lan_id':info[0],'lan_name':info[1],'iptype':'0','ip':info[2],'mask':info[3]}
        else:int_data = {'lan_id':info[0],'lan_name':info[1],'iptype':'1','ip':info[2],'mask':info[3]}
        requests.post(url=url,headers=headers,data=int_data,verify=False)

    def post_ext_ip(self, info):
        headers = {'Host': self.return_dut_ip(),
                   'Connection': 'keep-alive',
                   'Cache-Control': 'max-age=0',
                   'Origin': 'https://%s' % self.return_dut_ip(),
                   'Upgrade-Insecure-Requests': '1',
                   'Content-Type': 'application/x-www-form-urlencoded',
                   'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
                   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                   'Referer': 'https://%s/network/out_ipaddr/%s/%s' % (self.return_dut_ip(), info[0], info[1]),
                   'Accept-Encoding': 'gzip, deflate, br',
                   'Accept-Language': 'zh-CN,zh;q=0.9',
                   'Cookie': self.return_cookie()}
        url = 'https://%s/network/addip_outnet' % self.return_dut_ip()
        if ':' not in info[2]:
            ext_data = {'lan_id': info[0], 'lan_name': info[1], 'iptype': '0', 'ip': info[2], 'mask': info[3]}
        else:ext_data = {'lan_id': info[0], 'lan_name': info[1], 'iptype': '1', 'ip': info[2], 'mask': info[3]}
        requests.post(url=url, headers=headers, data=ext_data, verify=False)

    def post_int_proxy(self,info):
        headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Origin':'https://%s'%self.return_dut_ip(),
'Upgrade-Insecure-Requests':'1',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/network/in_iprule'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie': self.return_cookie()}
        url = 'https://%s/network/add_in_rule'%self.return_dut_ip()
        int_data = {'srcip':info[0],'app':info[1],'destip':info[2]}
        requests.post(url=url,headers=headers,data=int_data,verify=False)

    def post_ext_proxy(self, info):
            headers = {'Host': self.return_dut_ip(),
                       'Connection': 'keep-alive',
                       'Cache-Control': 'max-age=0',
                       'Origin': 'https://%s' % self.return_dut_ip(),
                       'Upgrade-Insecure-Requests': '1',
                       'Content-Type': 'application/x-www-form-urlencoded',
                       'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
                       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
                       'Referer': 'https://%s/network/out_iprule' % self.return_dut_ip(),
                       'Accept-Encoding': 'gzip, deflate, br',
                       'Accept-Language': 'zh-CN,zh;q=0.9',
                       'Cookie': self.return_cookie()}
            url = 'https://%s/network/add_out_rule' % self.return_dut_ip()
            int_data = {'srcip': info[0], 'app': info[1], 'destip': info[2]}
            requests.post(url=url, headers=headers, data=int_data,verify=False)

    def start_rule(self):
        #获取规则总数
        headers1 = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Upgrade-Insecure-Requests':'1',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/leftframe'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie':self.return_cookie()}
        url = 'https://%s/rules'%self.return_dut_ip()
        rsp = requests.get(url=url,headers=headers1,verify=False).text
        index = len(re.findall("value='\d{1,5}'",rsp))

        #分别启动规则
        headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Origin':'https://%s'%self.return_dut_ip(),
'Upgrade-Insecure-Requests':'1',
'Content-Type':'application/x-www-form-urlencoded',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Referer':'https://%s/rules'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie':self.return_cookie()}
        url = 'https://%s/rules/exec_rule'%self.return_dut_ip()
        select_data = {'startbtn':'启动选中规则'}
        for i in range(0,index):
            select_data['selected[]'] = str(i)
            print '正在启动(%d)条规则...'%(int(i)+1)
            requests.post(url=url,headers=headers,data=select_data,verify=False)

        #应用规则
        start_headers = {'Host':self.return_dut_ip(),
'Connection':'keep-alive',
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Accept':'*/*',
'Referer':'https://%s/topframe'%self.return_dut_ip(),
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'zh-CN,zh;q=0.9',
'Cookie':self.return_cookie()}
        url = 'https://%s/rules/apprule'%self.return_dut_ip()
        requests.get(url=url,headers=start_headers,verify=False)

    def main(self):

        #添加通道
        aisle = self.retrun_aisle()
        for i in aisle:
            self.post_aisle(i)
            print '正在添加通道: %s' % str(i)

        #添加时间
        self.post_time()
        print '正在添加时间: all-time'
        #添加对象
        obj = self.return_obj()
        for i in obj:
            self.post_obj(i)
            print '正在添加对象: %s'%str(i)

        #添加应用
        app = self.retrun_app()
        for i in app:
            self.post_app(i)
            print '正在添加应用: %s' % str(i)


        #添加规则
        rule = self.retrun_rule()
        for i in rule:
            self.post_rule(i)
            print '正在添加规则: %s' % str(i)

        #添加内网接口ip
        int_face_ip = self.retrun_int_interface()
        for i in int_face_ip:
            self.post_int_ip(i)
            print '正在添加内网接口ip: %s' % str(i)

        #添加外网接口ip
        ext_face_ip = self.retrun_ext_interface()
        for i in ext_face_ip:
            self.post_ext_ip(i)
            print '正在添加外网接口ip: %s' % str(i)

        # #添加内到外多ip对应规则
        int_proxy_info = self.retrun_int_proxy()
        for i in int_proxy_info:
            self.post_int_proxy(i)
            print '正在添加内到外多ip对应: %s' % str(i)

        # #添加外到内多ip对应规则
        ext_proxy_info = self.retrun_ext_proxy()
        for i in ext_proxy_info:
            self.post_ext_proxy(i)
            print '正在添加外到内多ip对应: %s' % str(i)

        #启动规则
        self.start_rule()
        raw_input('运行完成!!!')

if __name__ == '__main__':
    auto_rule = Auto_Rule()
    auto_rule.main()