A simple async Telegram bot that responds to the /ip command with the public IP address of the server where the bot is running.
The bot fetches the address using multiple external IP detection services in parallel for reliability, works behind NAT, and restricts access to a single authorized Telegram user defined in the configuration file.
- Async Telegram bot using python-telegram-bot
- Resilient parallel fetching from multiple IP providers (ipify.org, ident.me, ifconfig.me, ipinfo.io)
- Consensus-based validation - shows IP only when all providers agree
- Detailed status view - shows each provider's result with color-coded indicators
- Authorization based on Telegram user ID
- Dockerized deployment
- Configuration via environment variables
- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow the prompts to choose a name and username for your bot
- BotFather will give you a token like:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz - Save this token - you'll need it for configuration
- Open Telegram and search for @userinfobot
- Send
/startcommand - The bot will reply with your user ID (a number like
123456789) - Save this ID - only this user will be able to use your IP bot
Pull the latest image:
# Pull the image
docker pull ghcr.io/elisey/ipbot:latestCreate a .env file with your credentials:
TELEGRAM_TOKEN=your_bot_token_here
TELEGRAM_OWNER_ID=123456789Create a docker-compose.yml file:
services:
ip-bot:
image: ghcr.io/elisey/ipbot:latest
container_name: ipbot
env_file:
- .env
restart: alwaysStart the bot:
# Start the bot
docker compose up -d
# View logs
docker compose logs -f
# Stop the bot
docker compose downClone the repository:
git clone https://github.com/elisey/ipbot.git
cd ipbotCreate a .env file:
cp .env.example .env
# Edit .env and add your TELEGRAM_TOKEN and TELEGRAM_OWNER_IDRun with docker-compose:
docker compose up -dOpen Telegram and send /ip to your bot. It should respond with your public IP address.
The bot is configured via environment variables in the .env file:
TELEGRAM_TOKEN(required): Your bot token from @BotFatherTELEGRAM_OWNER_ID(required): Your Telegram user ID - only this user can use the botFETCHER_STRATEGY_ORDER(optional): IP fetchers to use, default:all
The bot supports multiple IP detection providers:
ipify- ipify.org JSON APIidentme- ident.me plain text APIifconfig- ifconfig.me plain text APIipinfo- ipinfo.io plain text APIcustom- custom plain text API
Example configurations:
# Use all fetchers (default - most reliable)
FETCHER_STRATEGY_ORDER=all
# Use specific fetchers only
FETCHER_STRATEGY_ORDER=ipify,identme,ifconfig
# Use only two fetchers
FETCHER_STRATEGY_ORDER=ipify,identme
# Use single fetcher (less reliable)
FETCHER_STRATEGY_ORDER=ipifyThe all keyword: When you set FETCHER_STRATEGY_ORDER=all, the bot automatically uses all available IP providers. This is the recommended configuration as it provides maximum reliability. If you add new custom fetchers to your deployment, they will automatically be included when using all.
The bot fetches your IP from all configured providers in parallel:
- All providers agree → Shows your IP with green checkmarks ✅
- Some providers fail → Shows IP if remaining providers agree, marks failures with ❌
- Providers return different IPs → Shows "unknown" and displays all results with
⚠️
Check your user ID:
- Verify
TELEGRAM_OWNER_IDin.envmatches your actual Telegram user ID - Get your ID from @userinfobot to confirm
Check bot token:
- Verify
TELEGRAM_TOKENis correct (no extra spaces) - Test the token by visiting:
https://api.telegram.org/bot<YOUR_TOKEN>/getMe
Your Telegram user ID doesn't match TELEGRAM_OWNER_ID in the configuration. Only the specified owner can use the bot.
# View bot logs
docker compose logs -f ip-bot
# View last 100 lines
docker compose logs --tail 100 ip-bot- Contributing Guide - Development setup, testing, and architecture
- Deployment Guide - Production deployment with Docker and systemd
MIT
