public-ip

A Python function to get your public IP address.


License
MIT
Install
pip install public-ip==0.11

Documentation

A Python function to get your public IP address.

Installation

pip install public-ip

Usage example

import public_ip as ip

ip.get()

Sample output:

212.51.139.31

How it works

The function queries in parallel six different websites...

  1. https://api.ipify.org
  2. https://checkip.amazonaws.com
  3. https://icanhazip.com
  4. https://ifconfig.co/ip
  5. https://ipecho.net/plain
  6. https://ipinfo.io/ip

... and returns the most common IP among the responses. In this manner (a) we don't depend on a single external service and (b) we can determine the IP correctly as long as a majority of these sites return the right value.

Test workflow PyPI badge Black badge