Hou op je raspberry het laatste IP adres bij dat je wordt toegekend door je provider. Stuur je bij wijziging een mail en zet ook dit ip adres op je users webruimte van je provider.
Hiervoor gebruiken we een gmail account met de
Onderstaand script: ScriptMailIP.sh, wordt elke 15 min onder de cron wordt gestart.
Dit script is geïnspireerd door: Email Extern Email Adress by CaptainKorhonen https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=65010
waar ik enkele aanpassing in heb gemaakt: hier de oorspronkelijke inleiding.
sudo apt-get update
sudo apt-get install mailutils smtp
Open daarna ssmtp.conf in een text editor
sudo nano /etc/ssmtp/ssmtp.conf
Edit de mailhun regel zodat het hierop lijk
mailhub=smtp.gmail.com:587
Voeg deze regels toe aan het einde van het bestand (vervang AuthUser en AuthPass waardes met jouw gmail adres en wachtwoord)
AuthUser=yourgmailaddress@gmail.com
AuthPass=yourgmailpassword
UseSTARTTLS=YES
Sla het bestand op en op revaliases in een text editor
sudo nano /etc/ssmtp/revaliases
Voeg onderstaande regel toe aan de onderkant van het bestand en verander het naar jouw gmail adres
root:yourgmailaddress@gmail.com:smtp.gmail.com:587
Mijn ssmtp.conf

Mijn revaliases

Settings gmail aanpassen
Om effectief een mail te kunnen doorsturen moet je een gmail account opzetten met de optie
optie “Apps met lagere beveiliging inschakelen!”. Daarom best een nieuwe specifieke account aanmaken bij gmail.
Gmail weigert anders een mail door te sturen van een ongekende mail app
Gebruikt ook geen uitroeptekens in je paswoord (linux)
https://www.google.com/settings/u/1/security/lesssecureapp

En nu het script door CaptainKorhonen
A quick explanation on how it works: When you run it for the first time, it retrieves your external IP address and stores it in a file called "ip.txt". This file will be created in the same folder as the script. Then, if the script is run again, it will load the previous IP address from the file, and will also check your current address. If these two match, i.e. the address has not changed, the script will just exit. If they do not match (the address has changed), the new IP address will be written to the text file (overwriting the old one) and emailed to you. Then the script will exit.
Put the subject of the message between the quotes in SUBJ, and the email address of the recipient between the quotes in EMAIL.
Hier het aangepaste script
Ik heb een andere routine gebruikt om het ip adres te vinden
dig +short myip.opendns.com @resolver1.opendns.com
met het curl commando wordt de file ip.txt opgeladen naar je provider.
curl --upload-file ip.txt ftp://my_provider_account:my_password@users.my_provider/

ScriptMailIP.sh
#!/bin/sh
SUBJ="IP_Provider"
EMAIL="my_email@my_provider"
ip1=""
ip2=""
#set ip1 to old ip address
read ip1 < ip.txt
#get your actual ip address and set it to ip2
ip2=$(dig +short myip.opendns.com @resolver1.opendns.com)
# if new address save it in ip.txt and mail it to you.
Put this address on your users home page created on your provider site if [ "$ip1" = "$ip2" ]
then
echo "$ip2" > ip.txt
# NEXT TWO LINES ARE ONLY ONE COMMANND LINE
curl --upload-file ip.txt ftp://my_provider_account:my_password@users.my_provider/
exit else
echo "$ip2" | mail -s $SUBJ $EMAIL
fiexit
Script uitvoeren
Met het commando
crontab –e
voegen we de volgende lijn toe aan de cron
0,15,30,45 * * * * sh /home/pi/ScriptMailIP.sh
Niet vergeten een blanco lijn toe te voegen in de cron!
Hier wordt elke 15 min een check of het IP adres uitgevoerd

In de body van de mail die naar je toe wordt gestuurd staat het laatste IP adres dat je provider heeft toegekend.
Op je users webruimte komt het bestand ip.txt terecht met als inhoud je laatste IPadres.
Als je buitenhuis bent, kan je altijd je laatste IP adres terug vinden, door in een webbrowser het adres: http:// users.provider/account_pseudomein/ip.txt in te voeren
Bvb voor telenet belgië wordt dit: http://users.telenet.be/”naam van je homepagina”/ip.txt
Jean-Marie