Created
August 20, 2025 14:21
-
-
Save davesie/bc206f70a6efd54ba72118a10b5e3ae4 to your computer and use it in GitHub Desktop.
Afraid.org IP Update and telegram notification
This file contains hidden or 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
| #!/bin/bash | |
| # Configuration - UPDATE THESE VALUES | |
| IP_FILE="/tmp/current_ip" | |
| BOT_TOKEN="" # Get from @BotFather on Telegram | |
| CHAT_ID="" # Your group chat ID (negative number) | |
| THREAD_ID="" # Topic thread ID (optional, remove if not using topics) | |
| UPDATE_URL="" # Your dynamic DNS update URL | |
| send_telegram() { | |
| local message="$1" | |
| curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \ | |
| -d "chat_id=$CHAT_ID" \ | |
| -d "message_thread_id=$THREAD_ID" \ | |
| -d "text=$message" | |
| } | |
| NEW_IP=$(curl -s --connect-timeout 10 https://ifconfig.io/ip) | |
| if [[ -z "$NEW_IP" ]]; then | |
| send_telegram "β οΈ Warning: Cannot reach ifconfig.io/ip - service appears to be down" | |
| echo "Error: Cannot reach ifconfig.io/ip" | |
| exit 1 | |
| fi | |
| if [[ ! -f "$IP_FILE" ]] || [[ "$NEW_IP" != "$(cat $IP_FILE)" ]]; then | |
| OLD_IP=$(cat "$IP_FILE" 2>/dev/null || echo "unknown") | |
| echo "$NEW_IP" > "$IP_FILE" | |
| send_telegram "ππ¨ IP ADDRESS CHANGED π¨π | |
| βββββββββββββββββββββββββββββββ | |
| π FROM: $OLD_IP | |
| π TO: $NEW_IP | |
| βββββββββββββββββββββββββββββββ" | |
| # Execute curl command when IP changes | |
| if curl -s "$UPDATE_URL"; then | |
| send_telegram "β SUCCESS! β | |
| π Dynamic DNS updated successfully!" | |
| echo "IP changed from $OLD_IP to $NEW_IP - curl command successful" | |
| else | |
| send_telegram "π¨ CRITICAL ERROR! π¨ | |
| β URGENT ACTION REQUIRED β | |
| βββββββββββββββββββββββββββββββββββββββββββββ | |
| β οΈ IP CHANGED BUT UPDATE FAILED! β οΈ | |
| π New IP: $NEW_IP | |
| π₯ Dynamic DNS update FAILED! | |
| π§ Manual intervention required! | |
| βββββββββββββββββββββββββββββββββββββββββββββ" | |
| echo "IP changed from $OLD_IP to $NEW_IP - curl command failed" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment