Skip to content

Instantly share code, notes, and snippets.

@Doooooo0o
Last active August 29, 2015 14:01
Show Gist options
  • Save Doooooo0o/18830c184799e8727c89 to your computer and use it in GitHub Desktop.
Save Doooooo0o/18830c184799e8727c89 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script require to have html2text on your computer
# [email protected]
###############################################################
vars(){
ipfile="/home/ip"
ip=$(curl -s monip.org|html2text |grep -i "ip :"|awk '{ print $3 }')
login="mondomaine.eu-mamachine"
pass="monsuperpass"
domain="mondomaine.eu"
url="http://$login:[email protected]/nic/update?system=dyndns&hostname=$domain&myip=$ip"
from="[email protected]"
mail="[email protected]"
genfile
}
genfile(){
if [ -f $ipfile ]; then
iplog=$(cat /home/ip)
else
touch /home/ip && echo $ip > $ipfile
iplog=$(cat /home/ip)
fi
compare
}
letscurl(){
curl -s $url
}
mailto(){
body="<head> <link rel='stylesheet' href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'> <script src='//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js'></script> </head> <h1>Changement d'IP</h1><br/><p><pre><b>$ip</b> est la nouvelle IP</pre></p>"
echo $body | mail \
-a "From: $from" \
-a "MIME-Version: 1.0" \
-a "Content-Type: text/html" \
-s "Changement d'IP pour : $ip" \
$mail
letscurl
}
compare(){
if [ $ip != $iplog ]; then
mailto
echo $ip > $ipfile && exit 0 || exit 1
else
return 0
fi
}
vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment