Maybe it’s useful for somebody.
Checks ip and sends to your email., if it has changed. Save as ipcheck.sh and put on /home/USER/
To check every hour, execute crontab -e and add this to the end:

0 * * * * sh ipcheck.sh

Here it goes:

#!/bin/sh

#########################
## uncomment and edit as needed
#########################
#mail_to="email@sapo.pt"
#mail_from="email@sapo.pt"
#user="email@sapo.pt"
#pass="password123"
#host_params="--host=smtp.sapo.pt --port=587 --tls=on --tls-starttls=on --auth=on"

#########################
## do not edit lines bellow
#########################
ip_old=""
ip_new=""
if [ -f ip.txt ]; then ip_old="$(cat ip.txt)";  fi
ip_new="$(curl --connect-timeout 10 --max-time 10 --retry 3 --retry-delay 0 -s icanhazip.com)"

if [ "$ip_new" != "" ] && [ "$ip_new" != "$ip_old" ]
then
echo $ip_new > ip.txt
printf "To:$mail_to\nSubject: IP\n\nOld ip = $ip_old\nNew ip = $ip_new" | msmtp --timeout=10 -t --from=$mail_from --user=$user --passwordeval="echo '$pass'" $host_params
fi
5 points

I would recommend always testing shell scripts with https://github.com/koalaman/shellcheck. Often there is room for improvement that you don’t think of yourself.

permalink
report
reply
1 point

Nice one. Did not know about it.

permalink
report
parent
reply
1 point

If you test it let us now how it’s worked with the script.

permalink
report
parent
reply
3 points

If you really need to access your home IP often, a domain is definitely worth it. Cloudflare sells them cheap, then just run something like cf-ddns that will update the DNS record automatically every time you get a new IP.

permalink
report
reply
2 points

Pretty useful, definitely going to save this.

My home IP almost never changes, so I’d hate to pay for a static IP.

permalink
report
reply
5 points

@Fubarberry @murkom noip.com has a free service I’ve used a bunch. Just run an app at home and select a domain. Some routers support the service too.

permalink
report
parent
reply
2 points

Thanks!

permalink
report
parent
reply
2 points

cool, I’ve been using curl -s ifconfig.me after dig +short myip.opendns.com stopped working

permalink
report
reply
2 points
*

I am using a python script that push in a private git repository (so I even have history). I am using dig +short myip.opendns.com @resolver1.opendns.com command to check ip.

permalink
report
reply

Linux

!linux@lemmy.ml

Create post

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word “Linux” in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

  • Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
  • No misinformation
  • No NSFW content
  • No hate speech, bigotry, etc

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

Community stats

  • 7.6K

    Monthly active users

  • 6.4K

    Posts

  • 176K

    Comments