提问人:Manas Agrawal 提问时间:11/2/2023 更新时间:11/2/2023 访问量:29
我的 python 代码没有在 pycharm 中运行。它开始并且永远不会结束,我也没有收到任何错误消息
My python code is not running in pycharm. It starts and never end and I also doesn't get any error message
问:
import nmap
from getmac import get_mac_address
from telegram import Bot
import asyncio
IP = '192.168.0.1'
KNOWN_DEVICES = []
TELEGRAM_BOT_TOKEN = '6577977517:AAFIqsW2UNE8d5HNyEEL2-3t_XK-8010scc'
CHAT_ID = '-4089379289'
class NetworkScanner:
def __init__(self, ip: str):
self.ip = ip
self.connected_devices = set()
def scan(self):
network = f"{self.ip}/24"
nm = nmap.PortScanner()
while True:
nm.scan(hosts=network, arguments='-sn')
host_list = nm.all_hosts()
for host in host_list:
mac = get_mac_address(ip=host)
print(mac)
if mac and mac not in self.connected_devices and mac not in KNOWN_DEVICES:
print("new Device Found")
self.notify_new_devices(mac)
self.connected_devices.add(mac)
async def send_telegram_message(self, bot, chat_id, message):
await bot.send_message(chat_id=chat_id, text=message)
def notify_new_devices(self, mac):
print("Notifying new device:", mac)
bot = Bot(token=TELEGRAM_BOT_TOKEN)
asyncio.run(self.send_telegram_message(bot, CHAT_ID, f"New Device Connected! MAc address : {mac}"))
if __name__ == "__main__":
scanner = NetworkScanner(IP)
scanner.scan()
我的 python 代码没有在 pycharm 中运行。它开始并且永远不会结束,我也没有收到任何错误消息。
我正在制作一个 python 程序,当新设备连接到我的电报机器人上的 wifi 网络时,我会收到通知
请帮我 #python #debugging #programming #telegram 机器人 #bots
答: 暂无答案
评论