Show public IP from shell

Sometime it happens you need to know your public ip address and maybe you're not at home or at office where you are aware of your public address. Maybe you're connected from a customer office or from a public place. There are services that need to configured in order to allow access accordingly to your public IP. I wrote this small script for fish shell. fish allows to extended its functionalities by placing scripts in the functions folder. Below the hierarchy of the fish folders under the user profile.

 1~/.config/fish
 2|
 3├── completions
 4├── conf.d
 5│   └── omf.fish
 6├── config.fish
 7├── fishd.madghigno-ThinkPad-T420
 8├── fish_variables
 9└── functions
10    ├── cik_dict
11    ├── fish_prompt.fish
12    ├── fish_right_prompt.fish
13    ├── getcik.fish
14    ├── lt.fish
15    ├── title.fish
16    ├── wanip.fish
17    └── weather.fish

The script is very simple:

1function wanip
2        echo "Your public ip address is:" ( set_color green && host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}')
3end

After you save the script in~/.config/fish/functions, you can invoke it from anywhere:

101:48:28 user $ wanip
2Your public ip address is: xxx.xxx.xxx.xxx

Another way to know you public ip is to open the browser and navigate a page which shows your public ip details. Below a couple of examples: