- Python Penetration Testing Cookbook
- Rejah Rehim
- 166字
- 2021-07-02 23:08:42
How to do it...
Let's try downloading a simple image file with the requests module. Open Python 2:
- As usual, import the requests library first:
>>> import requests
- Create an HTTP response object by passing a URL to the get method:
>>> response = requests.get("https://rejahrehim.com/images/me/rejah.png")
- Now send the HTTP request to the server and save it to a file:
>>> with open("me.png",'wb') as file: ... file.write(response.content)
If it's a large file, the response.content will be a large string and won't be able to save all the data in a single string. Here, we use the iter_content method to load the data in chunks.
- Here, we can create an HTTP response object as a stream:
response = requests.get("https://rejahrehim.com/images/me/rejah.png", stream = True)
- Then, send the request and save the file with the following command:
>>> with open("me.png",'wb') as file: ... for chunk in response.iter_content(chunk_size=1024): ... if chunk: ... file.write(chunk)
This will work in Python 3. Also, make sure you install the required libraries in the Python 3 environment.
推薦閱讀
- RESTful Java Web Services Security
- 為你護航:網絡空間安全科普讀本(第2版)
- API安全實戰
- Kali Linux Social Engineering
- 腦洞大開:滲透測試另類實戰攻略
- Metasploit Penetration Testing Cookbook(Third Edition)
- 從實踐中學習Kali Linux滲透測試
- 數據要素安全:新技術、新安全激活新質生產力
- End to End GUI Development with Qt5
- CTF特訓營:技術詳解、解題方法與競賽技巧
- Mastering Python for Networking and Security
- 網絡攻防實戰研究:MySQL數據庫安全
- 云計算安全技術與應用
- ATT&CK與威脅獵殺實戰
- CTF網絡安全競賽入門教程