Skip to content

Python script that sends you an email or a Telegram message if your IP address changes. Inspired in https://github.com/gexplorer/checkIP

Notifications You must be signed in to change notification settings

ipinto/checkIPy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

checkIPy

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

Installation

If you want to work with virtual environments:

  1. Read Managing Environments documentation.
  2. Create a virtual environment for this project: $ mkvirtualenv checkIPy.
  3. Then, when you want to work on this project: $ workon checkIPy.
  4. To stop using any virtual environment: $ deactivate.

You will need to install all the requirements: $ pip install -r requirements.txt.

Configuration

You must edit settings.py file with your configuration data in order to send emails or telegram messages.

Multiple devices

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'

Mail

Gmail configuration example:

# SMTP config
SMTP='smtp.gmail.com:587'
FROM='from_email@gmail.com'
USERNAME='from_email@gmail.com'
PASSWORD='password'

# Send email to
TO='to_email@gmail.com'

IP endpoint

By default we use ipify, but you can change the source to your preferred one.

# IP endpoint
IP_SOURCE='https://api.ipify.org'

Telegram bot

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.

Database configuration

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'

Run script

$ 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

Examples

  • 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

About

Python script that sends you an email or a Telegram message if your IP address changes. Inspired in https://github.com/gexplorer/checkIP

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages