Answer the question
In order to leave comments, you need to log in
Working with puthon 3.6 features?
Good day, experts!
I’m just starting to learn python, I’m writing a telegram bot for my needs, and a question arose about functions. I have code:
def solR(status):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('192.168.11.12',3389))
if result == 0:
status = 'Удаленка №1 - ОК'
else:
status = 'Удаленка №1 - Ошибка'
sock.close()
return status
status = ''
@bot.message_handler(commands=['Status'])
def welcome_status(message):
if autor(message.chat.id):
bot.send_message(message.chat.id, 'Статсус: \n' + solR(status))
Answer the question
In order to leave comments, you need to log in
def solR(status):
listip = ['192.168.11.12', '192.168.11.13', '192.168.11.14', '192.168.11.15']
liststatus = []
for x, ip in enumerate(listip, 1):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((ip,3389))
if result == 0:
liststatus.append(f'Удаленка №{x} - ОК')
else:
liststatus.append(f'Удаленка №{x} - Ошибка')
sock.close()
return '\n'.join(liststatus)
Удаленка №1 - Ошибка
Удаленка №2 - Ошибка
Удаленка №3 - ОК
Удаленка №4 - Ошибка
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question