Skip to content

Commit

Permalink
feat!: Also list local IP addresses
Browse files Browse the repository at this point in the history
BREAKING CHANGE: We now include the local IP addresses by default
  • Loading branch information
PurpleBooth committed Aug 3, 2024
1 parent ccfdea8 commit 69f3d8a
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 43 deletions.
103 changes: 95 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "CC0-1.0"
repository = "https://github.com/PurpleBooth/whatismyip"
categories = [ "development-tools", "command-line-utilities" ]
keywords = [ "dns", "ip", "resolve" ]
description = "Work out what your external ip is"
description = "Work out what your IP Address is"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -17,3 +17,4 @@ trust-dns-resolver = "0.23.2"
futures = "0.3.30"
tokio = { version = "1.39.2", features = ["full"] }
miette = { version = "7.2.0", features = ["fancy"] }
local-ip-address = "0.6.1"
73 changes: 52 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
# What is my ip

Check failure on line 1 in README.md

View workflow job for this annotation

GitHub Actions / lint-markdown / lint-markdown

This file is badly formatted, run "pandoc --from=gfm --to=gfm --wrap=auto './README.md'" to fix it --- ./README.md +++ /tmp/tmp.CGIAfJ/README.md @@ -1,6 +1,7 @@ # What is my ip -I made this tool as a convenient way to get my IPs, be they remote or local. +I made this tool as a convenient way to get my IPs, be they remote or +local. ## Usage @@ -137,14 +138,13 @@ ## How the WAN IP detection works -This is done by querying the -`o-o.myaddr.l.google.com` `TXT` record on the Google DNS servers -(`ns1.google.com`, `ns2.google.com`, `ns3.google.com`, or -`ns4.google.com`). +This is done by querying the `o-o.myaddr.l.google.com` `TXT` record on +the Google DNS servers (`ns1.google.com`, `ns2.google.com`, +`ns3.google.com`, or `ns4.google.com`). You can do the same thing yourself running using the [dig tool](https://en.wikipedia.org/wiki/Dig_(command)): ``` shell,skip() dig TXT +short o-o.myaddr.l.google.com @ns1.google.com -``` \ No newline at end of file +```

Work out what your external ip is. This is done by querying the
`o-o.myaddr.l.google.com` `TXT` record on the Google DNS servers
(`ns1.google.com`, `ns2.google.com`, `ns3.google.com`, or
`ns4.google.com`).

You can do the same thing yourself running using the [dig
tool](https://en.wikipedia.org/wiki/Dig_(command)):

``` shell,skip()
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
```

I made this tool as a convenient way to do the same thing, including
making multiple requests via only IPv4 and IPv6, so you can see both
your IPv4 and IPv6 addresses.
I made this tool as a convenient way to get my IPs, be they remote or local.

## Usage

Expand All @@ -23,16 +9,18 @@ whatismyip --help | sed 's/\.exe//'
```

``` text,verify(script_name="help",stream=stdout)
Work out what your external ip is
Work out what your IP Address is
Usage: whatismyip [OPTIONS]
Options:
-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
-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 you run it you should get an IP back
Expand All @@ -43,6 +31,7 @@ whatismyip

``` shell,skip()
207.105.7.192
192.168.1.56
```

It returns IPs and only IPs
Expand All @@ -53,6 +42,7 @@ whatismyip | grep -E '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|(([a-f0-9

``` shell,skip()
207.105.7.192
192.168.1.56
```

If you have an IPv4 address and an IPv6 address it'll list both
Expand All @@ -63,7 +53,9 @@ whatismyip

``` shell,skip()
207.105.7.192
192.168.1.56
2001:0db8:85a3:0000:0000:8a2e:0370:7334
fe80::4
```

And if you have only an IPv6 address it'll list that
Expand All @@ -74,6 +66,7 @@ whatismyip

``` shell,skip()
2001:0db8:85a3:0000:0000:8a2e:0370:7334
fe80::4
```

You can also force only v6 IPs
Expand All @@ -84,6 +77,7 @@ whatismyip -6

``` shell,skip()
2001:0db8:85a3:0000:0000:8a2e:0370:7334
fe80::4
```

Or v4s
Expand All @@ -94,6 +88,29 @@ whatismyip -4

``` shell,skip()
207.105.7.192
192.168.1.56
```

You can also get only IP Addresses local to your network interfaces

``` shell,script(name="local-only",expected_exit_code=0)
whatismyip -l
```

``` shell,skip()
192.168.1.56
fe80::4
```

Or only the WAN ones

``` shell,script(name="wan-only",expected_exit_code=0)
whatismyip -w
```

``` shell,skip()
207.105.7.192
2001:0db8:85a3:0000:0000:8a2e:0370:7334
```

You can also reverse those IPs, which is handy for checking VPNs and
Expand All @@ -117,3 +134,17 @@ build for linux and mac (all x86_64), alternatively use brew
``` shell,skip()
brew install PurpleBooth/repo/whatismyip
```

## How the WAN IP detection works

This is done by querying the
`o-o.myaddr.l.google.com` `TXT` record on the Google DNS servers
(`ns1.google.com`, `ns2.google.com`, `ns3.google.com`, or
`ns4.google.com`).

You can do the same thing yourself running using the [dig
tool](https://en.wikipedia.org/wiki/Dig_(command)):

``` shell,skip()
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
```
10 changes: 10 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use clap::Parser;

#[allow(
clippy::struct_excessive_bools,
reason = "This is the interface for the cli"
)]
#[derive(Parser, Debug, Copy, Clone)]
#[clap(author, version, about)]
pub struct Args {
/// Only print IP addresses local to this machine
#[clap(short = 'l', long = "only-local", conflicts_with = "only_wan")]
pub only_local: bool,
/// Only print IP addresses as seen by a remote service
#[clap(short = 'w', long = "only-wan", conflicts_with = "only_local")]
pub only_wan: bool,
/// Only print IPv4 addresses
#[clap(short = '4', long = "only-4", conflicts_with = "only_6")]
pub only_4: bool,
Expand Down
Loading

0 comments on commit 69f3d8a

Please sign in to comment.