예제 #1
0
 def _initCsrftoken(self):
     # 测试接口如果都需要先授权,可以在再次操作,将授权信息放到httpclient的headers或者cookies
     httpResponseResult = self.doRequest.get(
         "/horizon/auth/login/?next=/horizon/")
     cookies = httpResponseResult.cookies
     csrftoken = StrTool.getStringWithLBRB(cookies, 'csrftoken=', ' for')
     return csrftoken
예제 #2
0
def mitmproxy_init():
    mitmproxy_config = Read_Mitmproxy_Config().mitmproxy_config
    port = mitmproxy_config.proxy_port
    if "windows" == platform.system().lower():
        get_mitmproxy_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % port
        try:
            mitmproxy_process_id = subprocess.check_output(
                get_mitmproxy_process_id_command, shell=True)
            mitmproxy_process_id = mitmproxy_process_id.decode('utf-8')
            mitmproxy_process_id = StrTool.getStringWithLBRB(
                mitmproxy_process_id, 'LISTENING', '\r\n').strip()
            kill_mitmproxy_process_command = 'taskkill /F /pid %s' % mitmproxy_process_id
            try:
                print('%s关闭mitmproxy进程,进程id:%s,该进程监听已监听端口:%s' %
                      (DateTimeTool.getNowTime(), mitmproxy_process_id, port))
                subprocess.check_call(kill_mitmproxy_process_command,
                                      shell=True)
            except:
                print('%s关闭mitmproxy进程失败,进程id:%s,该进程监听已监听端口:%s' %
                      (DateTimeTool.getNowTime(), mitmproxy_process_id, port))
        except:
            print('%smitmproxy未查找到监听端口%s的服务' %
                  (DateTimeTool.getNowTime(), port))
    elif "linux" == platform.system().lower():
        # 获得当前mitmproxy所有进程id
        get_mitmproxy_process_ids_command = "ps -ef|grep 'mitmdump'|grep -v grep|awk '{print $2}'"
        try:
            mitmproxy_process_ids = subprocess.check_output(
                get_mitmproxy_process_ids_command, shell=True)
            mitmproxy_process_ids = mitmproxy_process_ids.decode('utf-8')
            get_lambda = lambda info: list(filter(None, info.split('\n'))
                                           ) if info else []
            mitmproxy_process_ids = get_lambda(mitmproxy_process_ids)
            if not len(mitmproxy_process_ids) > 0:
                print('%smitmproxy未查找到监听端口%s的服务' %
                      (DateTimeTool.getNowTime(), port))
            for mitmproxy_process_id in mitmproxy_process_ids:
                try:
                    print('%s关闭mitmproxy进程,进程id:%s,该进程监听已监听端口:%s' %
                          (DateTimeTool.getNowTime(), mitmproxy_process_id,
                           port))
                    subprocess.check_output("kill -9 " + mitmproxy_process_id,
                                            shell=True)
                except:
                    print('%s关闭mitmproxy进程失败,进程id:%s,该进程监听已监听端口:%s' %
                          (DateTimeTool.getNowTime(), mitmproxy_process_id,
                           port))
        except:
            print('%smitmproxy未查找到监听端口%s的服务' %
                  (DateTimeTool.getNowTime(), port))
    elif "darwin" == platform.system().lower():
        pass
    print('%s启动mitmproxy,使用端口%s' % (DateTimeTool.getNowTime(), port))
    p = multiprocessing.Process(target=start_mitmproxy, args=(port, ))
    p.daemon = True
    p.start()
예제 #3
0
 def T_1(self):
     get_process_id_command = 'netstat -ano|findstr "0.0.0.0:80"'
     #httpserver_process_id = subprocess.Popen(get_process_id_command, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     #print(httpserver_process_id.stdout.read().decode('gbk'))
     httpserver_process_id = subprocess.check_output(get_process_id_command,
                                                     shell=True)
     print(httpserver_process_id.decode('utf-8'))
     process_id = httpserver_process_id.decode('utf-8')
     #print(process_id)
     process_id = StrTool.getStringWithLBRB(process_id, 'LISTENING',
                                            '\r\n').strip()
예제 #4
0
def http_server_init():
    httpserver_config = Read_Http_Server_Config().httpserver_config
    port = httpserver_config.httpserver_port
    if "windows" == platform.system().lower():
        get_httpserver_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % port
        try:
            httpserver_process_id = subprocess.check_output(
                get_httpserver_process_id_command, shell=True)
            httpserver_process_id = httpserver_process_id.decode('utf-8')
            httpserver_process_id = StrTool.getStringWithLBRB(
                httpserver_process_id, 'LISTENING', '\r\n').strip()
            kill_httpserver_process_command = 'taskkill /F /pid %s' % httpserver_process_id
            print('###%s###1' % httpserver_process_id)
            try:
                print('关闭http.server进程,进程id:' + httpserver_process_id +
                      ',该进程监听已监听端口:' + port)
                subprocess.check_call(kill_httpserver_process_command,
                                      shell=True)
            except:
                print('关闭http.server进程失败,进程id:' + httpserver_process_id +
                      ',该进程监听已监听端口:' + port)
        except:
            print('http.server未查找到监听端口%s的服务' % port)
    elif "linux" == platform.system().lower():
        # 获得当前httpserver所有进程id
        get_httpserver_process_ids_command = "ps -ef|grep 'http.server %s'|grep -v grep|awk '{print $2}'" % port
        try:
            httpserver_process_ids = subprocess.check_output(
                get_httpserver_process_ids_command, shell=True)
            httpserver_process_ids = httpserver_process_ids.decode('utf-8')
            get_lambda = lambda info: list(filter(None, info.split('\n'))
                                           ) if info else []
            httpserver_process_ids = get_lambda(httpserver_process_ids)
            if not len(httpserver_process_ids) > 0:
                print('http.server未查找到监听端口%s的服务' % port)
            for httpserver_process_id in httpserver_process_ids:
                try:
                    print('关闭http.server进程,进程id:' + httpserver_process_id +
                          ',该进程监听已监听端口:' + port)
                    subprocess.check_output("kill -9 " + httpserver_process_id,
                                            shell=True)
                except:
                    print('关闭http.server进程失败,进程id:' + httpserver_process_id +
                          ',该进程监听已监听端口:' + port)
        except:
            print('http.server未查找到监听端口%s的服务' % port)
    elif "darwin" == platform.system().lower():
        pass
    print('启动http.server,使用端口' + port)
    p = multiprocessing.Process(target=start_http_server, args=(port, ))
    p.daemon = True
    p.start()
예제 #5
0
 def getXmindData(self):
     return StrTool.objectToJson(self.xmindData)
if __name__ == '__main__':
    report_config = Read_Report_Config().report_config
    ieport = report_config.web_ui_ie_port
    chromeport = report_config.web_ui_chrome_port
    firefoxport = report_config.web_ui_firefox_port
    if 'Windows' == platform.system():
        # 初始化进程池
        p_pool = Custom_Pool(3)
        if ieport:
            # 获得当前监听ie端口的进程id
            get_ieport_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % ieport
            try:
                get_allure_process_id = subprocess.check_output(
                    get_ieport_process_id_command, shell=True)
                get_allure_process_id = get_allure_process_id.decode('utf-8')
                get_allure_process_id = StrTool.getStringWithLBRB(
                    get_allure_process_id, 'LISTENING', '\r\n').strip()
                kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
                try:
                    subprocess.check_call(kill_allure_process_command,
                                          shell=True)
                except:
                    print('关闭allure进程,进程id:' + get_allure_process_id +
                          ',该进程监听已监听端口:' + ieport)
            except:
                print('allure未查找到监听端口%s的服务' % ieport)
            print('生成ie报告,使用端口' + ieport)
            print('ie报告地址:http://%s:%s/' % (Network.get_local_ip(), ieport))
            p = p_pool.apply_async(generate_windows_reports,
                                   ('output/web_ui/ie', ieport))
        if chromeport:
            # 获得当前监听chrome端口的进程id