用python批量添加保护站点

Posted gufengchen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用python批量添加保护站点相关的知识,希望对你有一定的参考价值。

最近在测试的过程中,由于一个bug的复现需要添加1600个保护站点,手工添加谁知到要何年何月,因此想到了用python进行自动化批量添加保护站点!

具体代码如下:

#!/usr/bin/env python
#-*- coding: utf-8 -*-

#author:       WangZhu
#contact:      isaac.zhu@dbappsecurity.com.cn
#dec:          add 1600 save station and click service  watch  console lo_to folk
#data:         write time is 2019/8/30

import time
from selenium import webdriver


time_start = time.time()
#-*-*-**--*-*-*-批量生成url文件-*-*-*-*-*-*-*-*
def get_ip(number=10, start=1.1.1.1):
    file = open(ip_list.txt,w)
    starts = start.split(.)
    A = int(starts[0])
    B = int(starts[1])
    C = int(starts[2])
    D = int(starts[3])
    for A in range(A, 256):
        for B in range(B, 256):
           for C in range(256):
              for D in range(D, 256):
                  ip = "%d.%d.%d.%d" % (A, B, C, D)

                  if number>1:
                      file.write(ip + \n)
                      number -= 1
                  elif number == 1:  # 解决最后多一行回车问题
                       file.write(ip)
                       number -= 1
                  else:
                    file.close()
                    print(ip)
                    return
              D = 0
           C = 0
        B = 0



#-*-*/-*-*/-*/-*-*-*创建1600个保护站点,并点击应用更改-*-*-*-*-*-*-*-
def createMoreStation():
    time.sleep(2)
    #打开ip地址列表文件
    ipfile = ip_list.txt
    global iplist
    iplist = 

    with open(ipfile, r) as file_to_read:
        for i in range(0, 2000):
            lines = file_to_read.readline()  # 整行读取数据
            if not lines:
                break
            ip = lines.replace(\n,  )
            iplist[i] = ip

    print(iplist[1])


    #输入url,username,password,并点击登录
    driver = webdriver.Chrome()
    driver.get("https://192.168.26.211")
    driver.maximize_window()
    time.sleep(2)
    driver.find_element_by_id("user_name").clear()
    driver.find_element_by_id("user_name").send_keys("admin")
    driver.find_element_by_id("user_pass").clear()
    driver.find_element_by_id("user_pass").send_keys("adminadmin")
    driver.find_element_by_id("user_login").click()
    time.sleep(2)
    # 点击配置
    print("点击配置")
    driver.find_element_by_xpath(/html/body/div/div[3]/ul/li[5]/a/span).click()
    # 点击保护站点
    print("添加保护站点")
    time.sleep(1)
    driver.find_element_by_xpath(/html/body/div/div[3]/ul/li[5]/ul/li[2]/a).click()
    time.sleep(2)
    print(添加保护站点)
    for i in range(0,1610):
        time.sleep(2)
        #添加保护站点
        driver.find_element_by_xpath(//*[@id="wrapper"]/div[4]/div[1]/div/div/div[4]/div[1]/div[2]/span[3]/a/span/span/label).click()
        #输入站点名称
        driver.find_element_by_id(webapp.name).send_keys(i)
        #输入站点IP
        driver.find_element_by_id(webapp.ip).send_keys(iplist[i])
        #点击链接协议
        driver.find_element_by_id(webapp-linkage-Protect1).click()
        #点击保存
        driver.find_element_by_xpath(//*[@id="wrapper"]/div[4]/div[1]/div/div/div[3]/div[11]/div[2]/table/tbody/tr/td[2]/a[1]/span/span/label).click()
    print(关闭浏览器)
    driver.close()



#批量添加保证站点
get_ip(10000, 101.23.228.102)
time_end = time.time()
time = time_end - time_start
print(耗时%s秒 % time)

createMoreStation()
print(执行结束)

注意:该文件在运行的过程中需要把谷歌驱动程序与主运行程序方在一起!

以上是关于用python批量添加保护站点的主要内容,如果未能解决你的问题,请参考以下文章

“警告:无法批量分配受保护的属性”

一旦内核空闲,如何通过添加进程在python中执行批量计算?

清华大佬教你用Python 批量加水印只需一行命令

zabbix调用api接口批量添加主机

尝试将 Jcrop 添加到 Paperclip 时无法批量分配虚拟属性

python mysql curros.executemany 批量添加