Gist
Shell script to ping public ip to telegram bot
Shell script to ping public ip to telegram bot
#!/bin/bash
# Your Telegram Bot Token (replace with your bot token)
BOT_TOKEN="your_bot_token_here"
# Your Telegram Chat ID (replace with your chat ID)
CHAT_ID="your_chat_id_here"
# Get the public IP address
PUBLIC_IP=$(curl -s https://api.ipify.org)
# Create a message with the current public IP
MESSAGE="Current public IP address is: $PUBLIC_IP"
# Telegram API URL
URL="https://api.telegram.org/bot$BOT_TOKEN/sendMessage"
# Send the IP to Telegram
curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$MESSAGE"
echo "IP address sent to Telegram: $PUBLIC_IP"
Fetching the BOT_TOKEN
- Use botfather on telegram to create a new bot and get the bot token.
Fetching the CHAT_ID
curl https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
This should share the list of latest chats and also the corresponding chat id for the chats.