简体   繁体   中英

How to get and change Public IP in Python?

I have been trying to get the live IP address in python and change it using a proxy server. The code I have seen is for local IP not the Public IP.

How can I get public IP using python? ie the IP I get from whatismyip , and can change the public IP using a proxy request in Python on windows.

There are multiple services you can use to get your ip. The one I use mostly is ipinfo.io/ip

You can use below code

import requests

proxies = {
  'http': 'http://<IP>:<PORT>',
  'https': 'http://<IP>:<PORT>',
}

req = requests.get('http://ipinfo.io/ip', proxies=proxies)
print (req.text)
  • you can get public ip address using hek .
import hek

# get ip 
ip = hek.ipstuff.myip(find="query")

# print ip
print(ip)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM