Skip to content

A simple utility that allows you to retrieve the WAN IP of your server for ssh or other needs.

Notifications You must be signed in to change notification settings

Klipar/GetWANIPTelegramBot

Repository files navigation

Get WAN IP Telegram Bot

Bash Script Python Docker Telegram

Logo Logo Logo

Ukrainian version 🇺🇦 ->

Get WAN IP Telegram Bot - is a simple utility that allows you to retrieve the WAN IP of your server in order to connect via SSH or for other purposes. This is useful when your router has a direct Internet connection (not through another local network), but you don’t have a static IP and you don’t have physical access to your server or its LAN to check the current WAN IP.


Installation

Requirements

Make sure you have the following installed:

  • bash
  • git
  • python >= 3.11
  • Python module venv

Download project files

Clone the repository:

git clone https://github.com/Klipar/GetWANIPTelegramBot.git

Go to the project directory:

cd GetWANIPTelegramBot

Generate and configure config files

Generate configs with the script generateConfig.sh:

bash generateConfig.sh

Edit the configuration file config/config.json using nano or any other text editor:

nano config/config.json

You need to configure the following parameters:

  • "API bot token" - your bot’s token. You can obtain it from Telegram bot @BotFather.
  • "registered users" - list of Telegram User IDs that will have access to the bot. You can get your ID using @userinfobot, just by typing /start.
  • "synthesize direct ssh connection command" - whether to generate a ready-to-use SSH connection command. If set to true, the following fields must be specified:
    • "server login" - the server’s login username (used in the generated SSH command).
    • "server ssh port" - the port forwarded from your router to the server (or the server’s own port if it is directly on the Internet).

⚠️ Note: the configuration file is only read at program startup. Changes will take effect only after restarting the bot.


Installing dependencies and creating a systemd service

If your Linux system uses systemd, you can install dependencies and create the service with:

bash setupAndStart.sh

If systemd is not available, do it manually:

python3 -m venv .venv
source ".venv/bin/activate"
pip install -r requirements.txt

Run the bot with:

.venv/bin/python main.py

Then you can add this command to autostart manually in your system.


Install using Docker

You can also run the bot with Docker and docker-compose. From the project directory, run:

docker-compose up

The bot will start, and you can use the same command to launch it later.


Stopping and removing the systemd service

To stop and remove the service, run:

bash stopAndDeleteService.sh

⚠️ This script does not delete the project directory or its files, it only stops and removes the service.

About

A simple utility that allows you to retrieve the WAN IP of your server for ssh or other needs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published