-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (27 loc) · 1.18 KB
/
Copy pathmain.py
File metadata and controls
37 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
import http.client
import re
from config.token import TOKEN
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
await message.reply("Введи /ip и узнай актуальный ip-адрес сервера")
@dp.message_handler(commands=['help'])
async def process_help_command(message: types.Message):
await message.reply("Введи /ip и узнай актуальный ip-адрес сервера")
# @dp.message_handler()
# async def echo_message(msg: types.Message):
# await bot.send_message(msg.from_user.id, msg.text)
@dp.message_handler(commands=['ip'])
async def process_ip_command(message: types.Message):
conn = http.client.HTTPConnection("ifconfig.me")
conn.request("GET", "/ip")
serverIP = conn.getresponse().read().decode('utf-8')
with open('/etc/ssh/sshd_config') as ssh:
port = re.search(r'Port ([0-9]+)', ssh.read()).group(1)
await message.reply(f'{serverIP}:{port}')
if __name__ == '__main__':
executor.start_polling(dp)