Skip to content

Instantly share code, notes, and snippets.

@davesie
Created August 20, 2025 14:21
Show Gist options
  • Select an option

  • Save davesie/bc206f70a6efd54ba72118a10b5e3ae4 to your computer and use it in GitHub Desktop.

Select an option

Save davesie/bc206f70a6efd54ba72118a10b5e3ae4 to your computer and use it in GitHub Desktop.
Afraid.org IP Update and telegram notification
#!/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