Skip to content

vterron/public-ip

Repository files navigation

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