Answer the question
In order to leave comments, you need to log in
How to combine text into 1 message?
import shodan
import config
import requests
import traceback
import telebot
from telebot import TeleBot
SHODAN_API_KEY = "PSKINdQe1GyxGgecYz2191H2JoS9qvgD"
api = shodan.Shodan(SHODAN_API_KEY)
ApiToken = config.API_TOKEN
bot = TeleBot(ApiToken)
def shodan(message):
try:
target = message.text
dnsResolve = 'https://api.shodan.io/dns/resolve?hostnames=' + target + '&key=' + SHODAN_API_KEY
try:
# First we need to resolve our targets domain to an IP
resolved = requests.get(dnsResolve)
hostIP = resolved.json()[target]
host = api.host(hostIP)
bot.send_message(message.chat.id,f"IP: %s" % host['ip_str'] + "\n" +"Organization: %s" % host.get('org', 'n/a') + "\n" + "Operating System: %s" % host.get('os', 'n/a'))
for item in host['data']:
bot.send_message(message.chat.id,"Порты: %s" % item['port'])
for item in host['vulns']:
CVE = item.replace('!','')
bot.send_message(message.chat.id,f'Уязвимости: %s' % item)
exploits = api.exploits.search(CVE)
except:
pass
except:
bot.send_message(messege.chat.id,"<code>По Shodan ничего не найдено</code>",parse_mode="html")
Answer the question
In order to leave comments, you need to log in
It is necessary to write the values into the variable in a loop, and then output them. In PHP, this is implemented using the usual concatenation, I suspect that in python the solution to the problem is similar.
First, do not shine SHODAN_API_KEY)
Answer:
ports = []
for item in host['data']:
ports.append(item['port'])
bot.send_message(message.chat.id, f"Порты: {ports}" )
ports = ""
for item in host['data']:
ports += str(item['port']) + ", "
bot.send_message(message.chat.id, f"Порты: {ports[:-2]}" )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question