Skip to content

PurpleBooth/whatismyip

Repository files navigation

What is my IP

A command-line utility for identifying both local and remote IP addresses of your machine.

Usage

whatismyip --help | sed 's/\.exe//'
Work out what your IP Address is

Usage: whatismyip [OPTIONS]

Options:
  -l, --only-local  Only print IP addresses local to this machine
  -w, --only-wan    Only print IP addresses as seen by a remote service
  -4, --only-4      Only print IPv4 addresses
  -6, --only-6      Only print IPv6 addresses
  -r, --reverse     Print the reverse DNS entries for the IP addresses
  -h, --help        Print help
  -V, --version     Print version

When executed, the tool displays your IP addresses:

whatismyip
207.105.7.192
192.168.1.56

The output consists solely of IP addresses, one per line

whatismyip | grep -E '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|(([a-f0-9:]+:+)+[a-f0-9]+)'
207.105.7.192
192.168.1.56

IP Version Support

By default, the tool displays both IPv4 and IPv6 addresses if available:

whatismyip
207.105.7.192
192.168.1.56
2001:0db8:85a3:0000:0000:8a2e:0370:7334
fe80::4

Filtering by IP Version

You can filter results to show only IPv6 addresses:

whatismyip -6
2001:0db8:85a3:0000:0000:8a2e:0370:7334
fe80::4

Or only IPv4 addresses:

whatismyip -4
207.105.7.192
192.168.1.56

Network Interface Filtering

Local Network Interfaces Only

To display only IP addresses from your local network interfaces:

whatismyip -l
192.168.1.56
fe80::4

WAN (External) IP Addresses Only

To display only your external IP addresses as seen by remote services:

whatismyip -w
207.105.7.192
2001:0db8:85a3:0000:0000:8a2e:0370:7334

Reverse DNS Lookup

The tool can perform reverse DNS lookups to display the hostname associated with each IP address. This is particularly useful for identifying VPN exit points or verifying network configurations:

whatismyip -r
207.105.7.192 (5898c708dfaf.dip0.t-ipconnect.de.)
2001:0db8:85a3:0000:0000:8a2e:0370:7334 (c06aa6b6af6c4ad5b46473d8d70bc068.dip0.t-ipconnect.de.)

Installation

Pre-built Binaries

Pre-compiled binaries for Linux and macOS (x86_64) are available on the releases page.

Using Homebrew

If you use Homebrew, you can install the tool with:

brew install PurpleBooth/repo/whatismyip

Technical Details

WAN IP Detection Mechanism

The tool determines your external IP address by querying a special DNS record that returns the client's IP address as seen by the DNS server. Specifically, it queries the o-o.myaddr.l.google.com TXT record on Google's DNS servers:

  • ns1.google.com
  • ns2.google.com
  • ns3.google.com
  • ns4.google.com

You can replicate this functionality manually using the dig tool:

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com