Exemple #1
0
def step_100msh0287(self):

    #修改门户认证的检查间隔为60s
    general_control.set_checkInterval(self,'60')
    general_control.apply(self)
    time.sleep(60)

    #上传tcpdump到路由器
    #调用ssh的默认登录ip,用户名和密码
    d = data.ssh_user()
    tcpdump_control.scp_to_remote('./data/BHU_tcpdump/tcpdump',d[0],d[1],d[2],'/usr/sbin/')
    tcpdump_control.scp_to_remote('./data/BHU_tcpdump/libpcap.so.1.3',d[0],d[1],d[2],'/usr/lib/')

    #ssh登录路由输入tcpdump抓包
    wanlog = capture_wan_packet()
    #将抓到的封包传输回本地pc
    tcpdump_control.scp_to_local(d[0],d[1],d[2],wanlog,'./data/')

    #打开本地下载的文件,读取文件内容
    f = open('./data/wanlog')
    log = f.read()
    f.close()

    '''#获取路由网关ID
    gw = general_control.get_gatewayId(self)
    #路由mac
    r_mac = ssh.ssh_cmd2("ifconfig eth0 | grep HWaddr | awk '{print$5}'")
    R_MAC = r_mac.upper()
    #路由版本
    r_version = ssh.ssh_cmd2('cat /etc/version/version')
    R_VERSION = r_version.upper()
    #路由无线mac
    wlan_mac = ssh.ssh_cmd2("ifconfig wlan0 | grep HWaddr | awk '{print$5}'")
    WLAN_MAC = wlan_mac.upper()'''

    #正确的心跳ping信息字符如下
    ping_str1 = 'GET /index/ping/?gw_id='
    #ping_str2 = 'route_mac=%s&route_version=%s&wlan_mac_0=%s'%(R_MAC,R_VERSION,WLAN_MAC)

    if ping_str1 in log:
        #ping信息在log信息中,说明有心跳信息,结果赋值1
        result = 1
    else:
        #ping信息不在log信息中,说明没有心跳信息,结果赋值0
        result = 0
    #结果返回给函数
    return result
    def test(self):
        print '1'
        ip = '192.168.11.1'
        user = '******'
        password = '******'
        #上传tcpdump到路由器
        tcpdump_control.scp_to_remote(
            '/home/zeng/PycharmProjects/BHU/data/BHU_tcpdump/tcpdump', ip,
            user, password, '/usr/sbin/')
        print '2'
        tcpdump_control.scp_to_remote(
            '/home/zeng/PycharmProjects/BHU/data/BHU_tcpdump/libpcap.so.1.3',
            ip, user, password, '/usr/lib/')

        print '3'
        #默认IP登录路由web页面
        web_user_password = data.default_web_user_password()
        interface_business.open_router_web(self, web_user_password[0])
        #登录路由
        login_control.set_user(self, web_user_password[1],
                               web_user_password[2])
        login_control.submit(self)
        time.sleep(3)
        #进入门户认证,修改网关ID
        general_control.wifidog_menu(self)
        print '4'
        #修改门户认证的检查间隔为60s
        general_control.set_checkInterval(self, '60')
        general_control.apply(self)
        time.sleep(60)
        print '5'
        #ssh登录路由输入tcpdump抓包
        tcpdump_control.tcpdump_command(user, ip, password,
                                        'tcpdump -i eth1 -s0 -w /tmp/wanlog')
        tcpdump_control.scp_to_local(ip, user, password, '/tmp/wanlog',
                                     '/home/zeng/')

        f = open('/home/zeng/wanlog')
        log = f.read()
        f.close()

        if 'GET /index/ping/?gw_id=' in log:
            print 'pass'
        else:
            print 'failed'
    def test(self):
        print '1'
        ip ='192.168.11.1'
        user = '******'
        password = '******'
        #上传tcpdump到路由器
        tcpdump_control.scp_to_remote('/home/zeng/PycharmProjects/BHU/data/BHU_tcpdump/tcpdump',ip,user,password,'/usr/sbin/')
        print '2'
        tcpdump_control.scp_to_remote('/home/zeng/PycharmProjects/BHU/data/BHU_tcpdump/libpcap.so.1.3',ip,user,password,'/usr/lib/')

        print '3'
        #默认IP登录路由web页面
        web_user_password = data.default_web_user_password()
        interface_business.open_router_web(self,web_user_password[0])
        #登录路由
        login_control.set_user(self,web_user_password[1],web_user_password[2])
        login_control.submit(self)
        time.sleep(3)
        #进入门户认证,修改网关ID
        general_control.wifidog_menu(self)
        print '4'
        #修改门户认证的检查间隔为60s
        general_control.set_checkInterval(self,'60')
        general_control.apply(self)
        time.sleep(60)
        print '5'
        #ssh登录路由输入tcpdump抓包
        tcpdump_control.tcpdump_command(user,ip,password,'tcpdump -i eth1 -s0 -w /tmp/wanlog')
        tcpdump_control.scp_to_local(ip,user,password,'/tmp/wanlog','/home/zeng/')

        f = open('/home/zeng/wanlog')
        log = f.read()
        f.close()

        if 'GET /index/ping/?gw_id=' in log:
            print 'pass'
        else:
         print 'failed'