protal认证的稳定性测试脚本

首先配置好环境,在控制台上进行设置:(1)设置保护区范围;(2)设置入网范围的ip,使其访问保护区时需要做相关认证;(3)设置例外管理,例外之内的机器无须做认证,直接到相关登录界面即可;(4)旁路开关打开,并打开网络接口和相应的端口(8080)

同时也需要对网络适配器上的网络端口进行对应的配置


需要相关技术:

伪装ip地址;

多线程运行;

打印debug日志

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


import os, sys
import re
import httplib
import time, threading
import urllib2, random 

fail_num = 0
fail_num_1 = 0
thread_num = 0
#filepath = 'C:\Users\zgc\Desktop\result.txt'

import logging

def initLogConf():
    LOG_FILE = "debug.log"
    logging.basicConfig(filename=LOG_FILE,level=logging.DEBUG)


def test_authentication():
    '''
    伪造ip地址,测试是否出现认证界面
    '''
    global fail_num
    a = random.randint(1,255)
    b = random.randint(0,255)
    c = random.randint(0,255)
    d = random.randint(0,255)
    ipAddress = "%d.%d.%d.%d" % (a,b,c,d)
    #ipAddress = "76.27.131.228"
    #a = 172
    #print ipAddress
    headers={"X-Forwarded-For":ipAddress,"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0"}
    conn = httplib.HTTPConnection("172.27.131.216:8080")
    conn.request("HEAD","/","",headers)
    time.sleep(5)
    res = conn.getresponse()
    #print res.getheaders()
    #print res.status,res.reason
    '''
    if a < 172:
        print res.getheaders()
        result = res.getheaders()
        req = urllib2.Request("http://172.27.131.216:8080%s" %(result[5][1]))
        print result[5][1]
        response = urllib2.urlopen(req)
        html = response.read().decode('utf-8')
        xre = r'(<title>)(.+)(</title>)'
        auth = re.search(xre, html).group(2)
        print auth
        auth_word = u"360新天擎"
        if auth != auth_word:
            fail_num_1 += 1
        else:
            continue
        response.close()
    else:
    '''
    conn.close()
    result = res.getheaders()
    #print result
    if result[2][1] != "http://172.27.131.156:8080/nac/register/login?url=172.27.131.216:8080":
        fail_num += 1
    else:
        print result[2][1]
        req = urllib2.Request(result[2][1])
        response = urllib2.urlopen(req)
        html = response.read().decode('utf-8')
        xre = r'(<title>)(.+)(</title>)'
        auth = re.search(xre, html).group(2)
        #print auth
        auth_word = u"企业安全准入控制系统"
        #重定向不是预期效果
        if auth != auth_word:
            fail_num += 1
        response.close()

def multi_threading(thread_num):

    thread_list = list();
    #thread_num = 100
    thread_num = random.randint(1,100)
    for i in range(0, thread_num):
        j = random.randint(1,10000)
        thread_name = "thread_%s" %j
        thread_list.append(threading.Thread(target = test_authentication, name = thread_name))

    for thread in thread_list:
        thread.start()
    
    for thread in thread_list:
        thread.join()


def run(interval):

    while True:
        try:
            time_remaining = interval-time.time()%interval
            time.sleep(time_remaining)
 
            multi_threading(thread_num)

            logging.info("[%s] fail_num: %d\n"%((time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())), fail_num))
        except Exception, e:
            print e

if __name__=="__main__":
    initLogConf()
    #间隔时间
    interval = 30
    #test_authentication()
    run(interval)
    #multi_threading(thread_num)
    #打印出总的失败次数
    #print fail_num


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值