IpTeller

Bene, ho preso l'adsl, l'ho configurata per funzionare sul mio Linux e funziona perfettamente: il collegamento pi veloce del mio vecchio modem e soprattutto sempre su!
Ma ahim, l'ip fisso mi costa troppo e ripiego sul dinamico. Come faccio ora a sapere l'ip a cui accedere da internet (con ssh, telnet, http o altro)?
Per questo ho creato questo script, che semplicemente mi manda una email coll'indirizzo ip aggiornato ogni volta che cambia.
Una alternativa interessante anche usare www.dyndns.org (fornisce un dns dinamico gratuito).


#!/bin/bash
#
# Write me for comments: [email protected]
#
# This script is intended to send the updated internet IP address to an email recpient (or more
# than one). It can be usefull if you have an Adsl or Cable connection with a dynamic IP address. Whenever
# your ISP changes you internet IP address, you will be notified with an email.
# So you will always know where to point your ssh ;-)
#
# Write this in your ip-up.local (usually in /etc/ppp/):
# /path_of_the_script/AdslInetAddress.sh
# If you don't have ip-up.local just create it:
# touch ip-up.local
# and make it executable:
# chmod 755 ip-up.local
#
# You will have to change a couple of lines in your /etc/sendmail.cf
# Write your smtp server where needed.
#
# "Smart" relay host (may be null)
# DSyour_smtp_here
#
# who I send unqualified names to (null means deliver locally)
# DRyour_smtp_here
#
# Change bin paths if necessary. My paths where intended for RedHat 7.2.
# It works, but feel free to modify and improve this script, since my scripting skills are quite poor!
# I hope this can help. Enjoy ;-)
#
#################################### BEGININNING OF THE SCRIPT #############################################
# Creates two files named "ipaddress" and "mailtext" containing something the first time you execute the script,
# or recreates the files should they be missing.

if [ ! -f ipaddress ];
then
echo first_time_usage > ipaddress
fi
if [ ! -f mailtext ];
then
echo first_time_usage > mailtext
fi

# Gets last known IP address from the file "ipaddress"
lastip=`cat ipaddress`
# Gets current IP address
# This points to ppp0, Change this accordingly to your inet configuration.
# I used grep and awk, but they could not work correctly on some systems other than RedHat 7.2.
# You could skip the usage of awk and would probably get something like this:
# "inet addr:xxx.xxx.xxx.xxx  Bcast:xxx.xxx.xxx.xxx  Mask:xxx.xxx.xxx.xxx" (with your real config)

ip=`ifconfig ppp0 | grep inet| awk '{ print $2 }'| awk -F : '{ print $2 }'`
# Checks if IP address has changed
if [ $ip != $lastip ];
then

# Writes new IP address (if it has changed) to file, and creates mail text.
echo $ip > ipaddress
echo Your IP address is now: $ip > mailtext

# Sends updated IP address to recipient. Change it as you need.
mail -s YourHostName[IPADDRESS:$ip] [email protected]
# Use this if you need multiple recipients. Change them as you need.
#mail -s YourHostName[IPADDRESS:$ip] -c [email protected] [email protected] [email protected]
date=`date`
echo $date -- IP CHANGED TO: $ip >> /var/log/ipchange.log

# Otherwise, if you still have the same IP address (lucky you!!!), it nicely exit with no action.
else
exit 0;
fi
exit;

######################################### END OF THE SCRIPT ################################################

Privacy Policy