Python script that sends you an email or a Telegram message if your IP address changes.
Inspired in checkIP project.
Only tested using Python 2.7.10
If you want to work with virtual environments:
- Read Managing Environments documentation.
- Create a virtual environment for this project:
$ mkvirtualenv checkIPy
. - Then, when you want to work on this project:
$ workon checkIPy
. - To stop using any virtual environment:
$ deactivate
.
You will need to install all the requirements: $ pip install -r requirements.txt
.
You must edit settings.py
file with your configuration data in order to send emails or telegram messages.
If you use this script in several devices, you can configure a name for each of them. This way, the name of the device will appear in the email subject or in the Telegram message.
If you leave it with an empty string, no name will be included.
# Multiple devices config
DEVICE_NAME='Raspberry pi'
Gmail configuration example:
# SMTP config
SMTP='smtp.gmail.com:587'
FROM='[email protected]'
USERNAME='[email protected]'
PASSWORD='password'
# Send email to
TO='[email protected]'
By default we use ipify, but you can change the source to your preferred one.
# IP endpoint
IP_SOURCE='https://api.ipify.org'
Check how to create a Telegram bot.
You should create your own bot and include in the configuration file your bot token:
# Telegram Bot
TELEGRAM_TOKEN='your_bot_token'
The app needs to know the chat id, so you must send a message to your bot in order to start working.
By default, your last IP is stored in the file data.db, but you can change the file name or location.
# Database
DB_FILE_NAME='data.db'
$ python checkIPy.py --help
usage: checkIPy.py [-h] [-d] [-c] [-e] [-t]
Check your external IP.
optional arguments:
-h, --help show this help message and exit
-d, --diff check if the IP changed since last time. If it didn't, it will do nothing.
-c, --console print your IP on console (default action)
-e, --email send an email with your IP
-t, --telegram send a Telegram message with your IP
-
Show my current IP:
$ python checkIPy.py
->1.2.3.4
-
Show my current IP and send me an email:
$ python checkIPy.py -ce
->1.2.3.4
-
Show my current IP only if it changed since last time:
$ python checkIPy.py --diff
->4.3.2.1
-
Show and send my current IP via email and Telegram only if it changed since last time:
$ python checkIPy.py -dcet