使用Python中的requests庫和第三方API來獲取外網(wǎng)IP地址

admin Python評論506字數(shù) 211閱讀模式

以下是一個示例代碼:

import requests
url = 'https://api.ipify.org' # 第三方API
response = requests.get(url)
ip_address = response.text
print(ip_address)

這個代碼使用了ipify.org提供的API來獲取IP地址。requests庫用于發(fā)送HTTP請求并獲取響應。獲取到的響應是一個字符串,其中包含了當前計算機的外網(wǎng)IP地址。文章源自網(wǎng)吧系統(tǒng)維護-http://hvig.cn/10576.html 文章源自網(wǎng)吧系統(tǒng)維護-http://hvig.cn/10576.html

版權聲明:文章圖片資源來源于網(wǎng)絡,如有侵權,請留言刪除!!!
廣告也精彩
admin
  • 本文由 發(fā)表于 2023年5月11日 20:09:08
  • 轉(zhuǎn)載請務必保留本文鏈接:http://hvig.cn/10576.html
匿名

發(fā)表評論

匿名網(wǎng)友 填寫信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: