0

I need to make a script that gets my public IP address from a website and prints it out.

#!/bin/bash
wget http://www.ipchicken.com/

grep

I don't know where to go from here.

Please help

annahri
  • 2,075

3 Answers3

4

You could use

wget -qO- https://api.ipify.org; echo

See the API usage on ipify.org.

Freddy
  • 25,565
1

What you're trying to do is fragile; it depends on the format of the HTML document returned by ipchicken, and that can change without warning. This currently works for me, your mileage may vary:

$ wget http://www.ipchicken.com/ -qO - | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
108.27.105.76
Andy Dalton
  • 13,993
0

You can use http://plain-text-ip.com/:

 wget -qO- http://plain-text-ip.com/; echo
 18?.1?.2?.5?