zoukankan      html  css  js  c++  java
  • Python requests 为pfsense 添加Routes

    # !/usr/bin/python 2
    #  -*- coding: utf-8 -*-
    __author__ = "Evilxr"
    
    import requests
    
    ips = open('ip_file','r')
    url2 = 'http://192.168.1.200/system_routes_edit.php'
    headers ={
        'Cookie': 'SLnewses=1; WPTLNG=1; PHPSESSID=4276cbd513477ddee8b290af31bfb15e',
        'Host': '192.168.1.200',
        'Referer': 'http://192.168.1.200/system_routes_edit.php',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0'
     }
    for ip in ips:
        ip = ip.strip()
        print ip
        b = ip.split('/')
        c,d = b[0],b[1]
        data = {
        'Submit':'Save',
        '__csrf_magic':'sid:ce2edaf249b5eaeaa057ec475ccbce2a12ca23c1,1422266972',
        'addinterfacegw':'wan',
        'addrtype':'IPv4',
        'descr':'', 
        'gateway':'WLAN2_PPPOE',
        'gatewaydescr':'',
        'gatewayip':'',
        'name':'GW',
        'network':c,
        'network_subnet':b
        }
        r = requests.post(url=url2,data=data,headers=headers)
    
    if 'System: Static Routes' in r.text:
        print 'success'
    

     ip_file格式:


    下面是删除脚本:


    # !/usr/bin/python 2
    #  -*- coding: utf-8 -*-
    __author__ = "Evilxr"
     
    import requests
    
    headers ={
        'Cookie': 'PHPSESSID=a29e08ae7683c423ba6f0a0139deb12c; SLnewses=1; WPTLNG=1',
        'Host': '192.168.1.200',
        'Referer': 'http://192.168.1.200/system_routes_edit.php',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0'
     }
    
    for i in range(1226)[::-1]:
        url2 = 'http://192.168.1.200/system_routes.php?act=del&id='+str(i)
        print 'deling--->',url2
        r = requests.get(url=url2,headers=headers)
    

  • 相关阅读:
    内置函数二
    内置函数
    【MySQL】纲举目张:打通MySQL架构和业务的任督二脉
    关闭服务器节能模式
    透明大页
    【MySQL】MySQ 8.0启用HugePage
    运维安全之Tripwire
    七字诀,不再憋屈的运维
    利用钉钉机器人发送告警信息
    【MySQL】MySQL 8.0支持utf8mb4
  • 原文地址:https://www.cnblogs.com/evilxr/p/4086609.html
Copyright © 2011-2022 走看看