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

3
  • 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?CommentedMar 9, 2020 at 1:09
  • 1
    what is your question? ... we should not have to guess what you want to know
    – jsotola
    CommentedMar 9, 2020 at 1:41
  • 1
    Does this answer your question? How can I get my external IP address in a shell script?
    – GAD3R
    CommentedMar 9, 2020 at 9:25

3 Answers 3

4

You could use

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

See the API usage on ipify.org.

    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 
    1
    • See @freddy 's answer; that doesn't depend on parsing the HTMLCommentedMar 9, 2020 at 1:30
    0

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

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

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.