When I call socket.getsockname()
on a socket object, it returns a tuple of my machine's internal IP and the port. However, I would like to retrieve my external IP. What's the cheapest, most efficient manner of doing this?
Type "cmd" in the search box in the Start Menu or taskbar and click the Command Prompt icon to open the Windows command prompt. Type "ipconfig" in the command prompt window and take note of the IP address displayed.
An external IP address is the address assigned to you by your ISP (Internet service provider) that the Internet and other computers outside your local network use to identify you.
The most simple method of getting a public IP is by using this
import requests
IP = requests.get('https://api.ipify.org/').text
print(f'Your IP is: {IP}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With