Create a telegram bot to scan IP/host/websites (enter the IP and get the fastest open port report)
Create Telegram bot Scan.py:
⚡️ First, install the necessary libraries:
⚡️ Create a file Filename.py
⚡️ Go to BotFather and create a new Telegram Bot
⚡️ Save the script as Filename.py Source
⚡️ Execute the 'Scan.py' script, and visit your Telegram bot, type '/start' to receive the welcome message.
⚡️ Pass the IP/host and get open ports, service and versions.
#nmap @NxSMind #python_Telegram_Bot
@CodingCoursePro
Shared with Love➕
NOTE: This post serves as a demonstration for creating a Python application. I do not endorse spamming or violating the terms or services of any individuals.
Create Telegram bot Scan.py:
⚡️ First, install the necessary libraries:
$ pip install python-telegram-bot==13.7
$ pip install python-nmap
⚡️ Create a file Filename.py
⚡️ Go to BotFather and create a new Telegram Bot
⚡️ Save the script as Filename.py Source
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import nmap
bot = telegram.Bot(token='8371237947:Aeo3bq8qEJP2kipYIPC_JhwFOIGk5bU')
updater = Updater('8371237947:Aeo3bq8qEJP2kipYIPC_JhwFOIGk5bU', use_context=True)
dispatcher = updater.dispatcher
nm = nmap.PortScanner()
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Welcome there ! Please pass the IP or Host.")
def scan(update, context):
try:
target = update.message.text
nm.scan(hosts=target, arguments='-T4 -F')
scan_result = ''
for host in nm.all_hosts():
scan_result += f"Host: {host}\n"
for proto in nm[host].all_protocols():
ports = nm[host][proto].keys()
for port in ports:
port_info = nm[host][proto][port]
scan_result += f"Port: {port} State: {port_info['state']} Service: {port_info['name']}"
if 'product' in port_info:
scan_result += f", Version: {port_info['product']}"
scan_result += "\n"
context.bot.send_message(chat_id=update.effective_chat.id, text=scan_result)
except Exception as e:
context.bot.send_message(chat_id=update.effective_chat.id, text=f"Error: {str(e)}")
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
message_handler = MessageHandler(Filters.text & ~Filters.command, scan)
dispatcher.add_handler(message_handler)
updater.start_polling()
updater.idle()
⚡️ Execute the 'Scan.py' script, and visit your Telegram bot, type '/start' to receive the welcome message.
⚡️ Pass the IP/host and get open ports, service and versions.
#nmap @NxSMind #python_Telegram_Bot
@CodingCoursePro
Shared with Love
Please open Telegram to view this post
VIEW IN TELEGRAM
🥰1