Reputation: 123
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? i.e. the IP I get from whatismyip, and can change the public IP using a proxy request in Python on windows.
Upvotes: 1
Views: 4679
Reputation: 26
You can also retrieve your public ip using ident:
import requests
response = requests.get('https://ident.me')
if response.status_code == 200:
print(f"IP >>> {response.content.decode('utf8')}")
Upvotes: 1
Reputation: 1
import hek
# get ip
ip = hek.ipstuff.myip(find="query")
# print ip
print(ip)
Upvotes: 0
Reputation: 146630
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)
Upvotes: 2