A simple, lightweight but powerfull telegram bot that sends your public IP through telegram in case it changes, really useful if you have dynamic IPs but also have a private cloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Every minute, perfect for IP_INFO free tier | |
* * * * * /usr/bin/python3 /PATH_TO_THE_SCRIPT/ipbot.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telebot | |
from telebot import types | |
import os | |
import requests | |
import json | |
TOKEN = 'BOT_TOKEN' | |
ip = "YOUR_INITIAL_IP" | |
def get(): | |
endpoint = 'https://ipinfo.io/json?token=IPINFO_TOKEN' | |
response = requests.get(endpoint, verify = True) | |
if response.status_code != 200: | |
return '' # 'Status:', response.status_code, 'Problem with the request. Exiting.' | |
exit() | |
data = response.json() | |
return data['ip'] | |
bot = telebot.TeleBot(TOKEN) | |
cid = YOUR_CHAT_TELEGRAM_ID | |
newIp = get() | |
previous = open("ROUTE_TO_THE_FILE/ip", "r").read() | |
if(newIp != previous and newIp != ""): | |
f = open('ROUTE_TO_THE_FILE/ip','w') | |
print(newIp) | |
f.write(newIp) | |
f.close() | |
bot.send_message(cid, newIp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment