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,030
  • 14
  • 32
  • 1
    What do you mean by "get my ip address from a website and print it out"? Do you just want the ip address of the site itself? – Nasir Riley Mar 09 '20 at 01:09
  • 1
    what is your question? ... we should not have to guess what you want to know – jsotola Mar 09 '20 at 01:41
  • 1
    Does this answer your question? [How can I get my external IP address in a shell script?](https://unix.stackexchange.com/questions/22615/how-can-i-get-my-external-ip-address-in-a-shell-script) – GAD3R Mar 09 '20 at 09:25

3 Answers3

4

You could use

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

See the API usage on ipify.org.

Freddy
  • 25,172
  • 1
  • 21
  • 60
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,654
  • 1
  • 25
  • 45
0

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

 wget -qO- http://plain-text-ip.com/; echo
 18?.1?.2?.5?
schrodingerscatcuriosity
  • 12,087
  • 3
  • 29
  • 57