I would like to log my external IP, i.e. the WAN IP address of the router, on an RPi4 unit, which sits on a mobile broadband connection.
It seems like the external IP address changes frequently so I would like to create a log of the address.
I can do all items in a script except I don't know how to retrieve the address....
If I use this command in a browser I get a response in the browser window:
http://checkip.dyndns.com/
The displayed text in the browser is this:
Current IP Address: 158.174.yyy.xxx
(yyy.xxx are real numbers of course)
Can you advice some way I can use that URL inside a script and extract the IP address response into a variable?
How to read external IP address into a variable in a script?
Bo Berglund
Sweden
Sweden
Re: How to read external IP address into a variable in a script?
In bash, the following works for me
There might be easier ways.
Code: Select all
myip="$(wget -q -O - "http://checkip.dyndns.com/" | sed "s/^.*: \([0-9.]*\)<.*$/\1/")"
echo "My IP address is: $myip"
Unreadable squiggle
Re: How to read external IP address into a variable in a script?
Thanks!
I think it is easy enough - it is working fine!
I think it is easy enough - it is working fine!
Bo Berglund
Sweden
Sweden