init
This commit is contained in:
parent
d38e1b5476
commit
604bedb66c
40
README.md
40
README.md
@ -1 +1,39 @@
|
||||
# telegram-ping-ip
|
||||
# Telegram Bot for Sending IP-address of a server if Dynamic IP has changed.
|
||||
** Inspired by [indicozy/telegram-ping-ip](https://github.com/indicozy/telegram-ping-ip)
|
||||
|
||||
## Getting started.
|
||||
### Requirements:
|
||||
* `curl` - Install with whatever package manager you use
|
||||
* `screen` - *Optional* requirement to run script in background.
|
||||
|
||||
|
||||
### Clone repo and Configure
|
||||
```bash
|
||||
git clone https://github.com/shihaamabr/telegram-ping-ip.git
|
||||
cd telegram-ping-ip
|
||||
chmod +x telegram-ping-ip.sh screen-telegram-ping-ip.sh
|
||||
cp env.sample .env
|
||||
```
|
||||
- Edit the contents of .env to your config (`nano .env`)
|
||||
### Execute the script
|
||||
```bash
|
||||
./telegram-ping-ip.sh
|
||||
```
|
||||
### Run the script in a screen
|
||||
```bash
|
||||
./screen-telegram-ping-ip.sh
|
||||
```
|
||||
### Automatically run the script on system boot up
|
||||
* Add it to a crontab `crontab -e` \
|
||||
```
|
||||
@reboot /bin/bash /path/to/telegram-ping-ip/screen-telegram-ping-ip.sh
|
||||
```
|
||||
## Future plans
|
||||
* create a daemon, idk, it seems interesting
|
||||
|
||||
|
||||
## Additional Information
|
||||
**FYI IT pings to `whatismyip.shihaam.me` by default, this can be configured in .env to use `ifconfig.me` or whatever else server.**
|
||||
|
||||
## Bugs
|
||||
- [You tell me :)](https://github.com/shihaamabr/telegram-ping-ip/issues/new)
|
||||
|
7
env.sample
Normal file
7
env.sample
Normal file
@ -0,0 +1,7 @@
|
||||
TG_BOT_TOKEN='' #Your Telegram Bot API Token, Contact @BotFather on Telegram to obtain token
|
||||
TG_CHATID='' #Your Telegram chat ID, This could be your user, group, supergroup or channel ID, add "-100" first if supergroup or channel
|
||||
|
||||
#Optional Config
|
||||
DELAY='3600' #Defines how often in seconds to check for IP address changes
|
||||
TG_BOTAPI='https://api.telegram.org/bot' #Change if you'd like to use another Telegram Bot API host
|
||||
WHATISMYIP='https://whatismyip.shihaam.me' #Website that returns visitor IP address, (eg: https://ifconfig.me/ip/)
|
25
telegram-ping-ip.sh
Normal file
25
telegram-ping-ip.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
source .env 2> /dev/null #Import Credentials
|
||||
|
||||
#Check for missing configration
|
||||
if [ ! -f .env ] || [ "$TG_BOT_TOKEN" = "" ] || [ "$TG_CHATID" = "" ]
|
||||
then
|
||||
echo Not Configured! Please 'cp env.sample .env' edit .env and run this script again.
|
||||
fi
|
||||
|
||||
FethchIP(){
|
||||
NEW_IP=$(curl -s $WHATISMYIP)
|
||||
}
|
||||
SendToTelegram(){
|
||||
curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=IP%20is%20$NEW_IP > /dev/null
|
||||
}
|
||||
while true; do
|
||||
FethchIP
|
||||
if [ "$NEW_IP" != "$OLD_IP" ]
|
||||
then
|
||||
SendToTelegram
|
||||
OLD_IP=$NEW_IP
|
||||
:
|
||||
fi
|
||||
sleep $DELAY
|
||||
done
|
Loading…
x
Reference in New Issue
Block a user