Python requests 为pfsense 添加Routes

时间:2021-04-10 07:42:27
# !/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格式:

Python requests 为pfsense 添加Routes


下面是删除脚本:


# !/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)

Python requests 为pfsense 添加Routes