網站首頁 編程語言 正文
一、python批量查詢練習
通過接口批量查詢該ip是否屬于指定接口:
import requests import json if __name__ == "__main__": ? ? ? ? headers = { ? ? ? ? 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36' ? ? } ? ? # 獲取源IP ? ? with open('./ip.txt','r') as fp: ? ? ? ?list_ip = fp.readlines() ? ? ? ?# ?處理每個ip后面對\n ? ? ? ?for li in list_ip: ? ? ? ? ? li = li.rstrip() ? ? ? ? ? url="http://www.xxxx.com/api/query_ip?ip={0}&flag=1&key=cdbcbdhbhcbdhcbhdbchdbchdbch&user=root".format(li) ? ? ? ? ? # ? ? ? ? ? result_json = requests.get(url, headers=headers) ? ? ? ? ? # print(result_json.json()) ? ? ? ? ? # 獲取到數據和未獲取到數據最終打印對結果要不一樣 ? ? ? ? ? if result_json.json()['total'] == 0: ? ? ? ? ? ? ? cw_url="http://www.sss.cn/api/query_ip?ip={0}&flag=1&key=fjdifjdifncjdnjcndjhfjndjnjdhfjdhj&user=root".format(li) ? ? ? ? ? ? ? cw_result_json = requests.get(cw_url,headers=headers) ? ? ? ? ? ? ? print("XXX科技CMDB未發現該資產 ->",end="") ? ? ? ? ? ? ? if cw_result_json.json()['total']==0: ? ? ? ? ? ? ? ? ? print(li + " <- SSSSCMDB未發現該資產") ? ? ? ? ? ? ? ? ? print(result_json.json(),cw_result_json.json()) ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? print("該資產屬于SSSSCMDB:") ? ? ? ? ? ? ? ? ? ip1 = cw_result_json.json()['data'][0]['ip1'] ? ? ? ? ? ? ? ? ? company = cw_result_json.json()['data'][0]['company'] ? ? ? ? ? ? ? ? ? profile_center = cw_result_json.json()['data'][0]['profit_center'] ? ? ? ? ? ? ? ? ? platform = cw_result_json.json()['data'][0]['platform'] ? ? ? ? ? ? ? ? ? leader = cw_result_json.json()['data'][0]['leader'] ? ? ? ? ? ? ? ? ? email = cw_result_json.json()['data'][0]['email'] ? ? ? ? ? ? ? ? ? print(ip1 + ' ?' + company + ' ?' + profile_center + ' ?' + platform + ' ?' + leader + ' ?' + email) ? ? ? ? ? else: ? ? ? ? ? ? ? ip1 = result_json.json()['data'][0]['ip1'] ? ? ? ? ? ? ? company = result_json.json()['data'][0]['company'] ? ? ? ? ? ? ? profile_center = result_json.json()['data'][0]['profit_center'] ? ? ? ? ? ? ? platform = result_json.json()['data'][0]['platform'] ? ? ? ? ? ? ? leader = result_json.json()['data'][0]['leader'] ? ? ? ? ? ? ? email = result_json.json()['data'][0]['email'] ? ? ? ? ? ? ? print(ip1 + ' ?' + company + ' ?' + profile_center + ' ?' + platform + ' ?' + leader + '?
二、python批量請求(GET | POST)
本案例為普通的測試案例,主要用于測試通過get
請求和post
請求產生響應是否一致,主要針對響應碼為200的結果進行輸出,沒有什么技術含量!
#-*- coding:utf-8 -*- import requests def apiRequest(): ? ? header = { ? ? ? ? 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36', ? ? ? ? 'Cookie': 'JSESSIONID=E65BD767F22CBEFE30BAF33D84A59072', ? ? ? ? 'Referer':'http://aaa.xxx.com', ? ? ? ? 'Content-Type':'application/json;' ? ? } ? ? with open('url.txt','r',encoding='utf-8') as fp: ? ? ? ? urls = fp.readlines() ? ? ? ? for li in urls: ? ? ? ? ? ? get_response = requests.get(url=li,headers=header) ? ? ? ? ? ? post_response = requests.post(url=li, headers=header) ? ? ? ? ? ? if get_response.status_code == 200 or post_response.status_code == 200: ? ? ? ? ? ? ? ? print(li.strip()+"請求測試結果如下:") ? ? ? ? ? ? ? ? print("GET請求測試結果",get_response.content) ? ? ? ? ? ? ? ? print("POST請求測試結果", post_response.content) if __name__ == '__main__': ? ? apiRequest()
三、python列表轉集合練習
#處理字符串重復問題—本練習用于fuzz
字典去重
if __name__ == '__main__': ? ? with open('E:/xilie/web/fuzzDicts-master/apiDict/api.txt','r') as fp: ? ? ? ? list1 = fp.readlines() ? ? ? ? list2 = set(list1) ? ? ? ? print("去重前的條數:"+str(len(list1))) ? ? ? ? print(type(list2), "去重后的條數"+str(len(list2))) ? ? with open('E:/xilie/web/fuzzDicts-master/apiDict/new_api.txt','w+') as fp1: ? ? ? ? for li1 in list2: ? ? ? ? ? ? fp1.write(li1) ? ? ? ? print("已將去重內容寫入新文件!?。?)
原文鏈接:https://blog.csdn.net/weixin_42380348/article/details/120494003
相關推薦
- 2022-03-14 如何在Git hub上快速查找合適的項目(如何在github上找到自己想要的代碼)
- 2022-05-17 MacOS系統(macmini macbook pro)上安裝RabbitMQ
- 2022-12-07 org.apache.tomcat.util.http.fileupload.IOUtils報錯對應
- 2022-09-24 python的numpy模塊實現邏輯回歸模型_python
- 2022-11-30 關于頁面加載即執行JQuery的三種方法小結_jquery
- 2022-10-29 RHCSA 文件編輯 nano vi vim
- 2022-06-19 python繪制橫豎條形圖的方法_python
- 2024-01-11 redis開啟密碼驗證
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支