because some commands do not show the output?

0

I'm making a server and client. Everything is fine, but in the shell when I have the client.py running and when I insert some commands like rm -r , shred -u ... it executes correctly in the shell of the other computer, but in my client's terminal it stays as if it had not been executed, that is, like this:

1.0.0.0@nombre_pc:$shred -u texto
|

while in commands like ls prints an output:

$ls
Descargas
Documentos
Escritorio
Imágenes
Música
Plantillas
Público
snap
Videos
1.0.0.0@nombre_pc:$

server.py:

#!/usr/bin/env python
#-*- coding:utf-8 -*-
#Se importa el módulo
import socket, os, getpass, shutil, shlex, commands
from subprocess import Popen, PIPE
name_host_server = getpass.getuser()
carpeta_actual_server = os.getcwd()
#instanciamos un objeto para trabajar con el socket
ser = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server = ""
port = 8000
#Puerto y servidor que debe escuchar
ser.bind((server, port))
#Aceptamos conexiones entrantes con el metodo listen. Por parámetro las 
conexiones simutáneas.
ser.listen(1)

#Instanciamos un objeto cli (socket cliente) para recibir datos
cli, addr = ser.accept()
while True:
#Recibimos el mensaje, con el metodo recv recibimos datos. Por parametro la cantidad de bytes para recibir
recibido = cli.recv(1024)
cd_recibido = recibido.count("cd")
text_recibido = recibido.count("-t") 
ventana_error_recibido = recibido.count("-m --error") #ok
ventana_info_recibido = recibido.count("-m --info") #ok
ventana_input_recibido = recibido.count("-m --input") #ok
ventana_question_recibido = recibido.count("-m --question") #ok
ventana_warning_recibido = recibido.count("-m --alert") #ok
ventana_notification_recibido = recibido.count("-m --notification") #ok
if text_recibido == 1:
    texto_filtro = recibido.replace("-t ","")
    print(texto_filtro)
    cli.send(texto_filtro)
elif cd_recibido == 1:
    texto_filtro = recibido.replace("cd ","")
    os.chdir(texto_filtro)
    cli.send(texto_filtro)
elif ventana_input_recibido == 1:
    texto_filtro = recibido.replace("-m --input ","")
    comando = shlex.split("zenity --entry --title '' --text %s --display :0" % texto_filtro);
    proceso = Popen(comando, stdout=PIPE, stderr=PIPE)
    salida = proceso.stdout.read()
    cli.send(salida)
elif ventana_error_recibido == 1:
    texto_filtro = recibido.replace("-m --error ","")
    comando = shlex.split("zenity --error --title '' --text %s --display :0" % texto_filtro);
    proceso = Popen(comando, stdout=PIPE, stderr=PIPE)
    salida = proceso.stdout.read()
    cli.send(salida)
elif ventana_info_recibido == 1:
    texto_filtro = recibido.replace("-m --info ","")
    comando = shlex.split("zenity --info --title '' --text %s --display :0" % texto_filtro);
    proceso = Popen(comando, stdout=PIPE, stderr=PIPE)
    salida = proceso.stdout.read()
    cli.send(salida)
elif ventana_notification_recibido == 1:
    texto_filtro = recibido.replace("-m --notification ","")
    comando = shlex.split("zenity --notification --title '' --text %s --display :0" % texto_filtro);
    proceso = Popen(comando, stdout=PIPE, stderr=PIPE)
    salida = proceso.stdout.read()
    cli.send(salida)
elif ventana_warning_recibido == 1:
    texto_filtro = recibido.replace("-m --alert ","")
    comando = shlex.split("zenity --warning --text %s --display :0" % texto_filtro);
    proceso = Popen(comando, stdout=PIPE, stderr=PIPE)
    salida = proceso.stdout.read()
    cli.send(salida)
elif ventana_question_recibido == 1:
    texto_filtro = recibido.replace("-m --question ","")
    comando = shlex.split("zenity --question --title '' --text %s --display :0" % texto_filtro);
    proceso = Popen(comando, stdout=PIPE, stderr=PIPE)
    salida = proceso.stdout.read()
    cli.send(salida)
else:
    salida = commands.getoutput(recibido)
    cli.send(salida)           
if ser == True:
    print("Conexion cerrada")
#Cerramos la instancia del socket cliente y servidor
cli.close()
ser.close()

The problem must come from here:

    else:
       salida = commands.getoutput(recibido)
       cli.send(salida) 

But I do not know what the error is

Client:

#!/usr/bin/env python
#-*- coding_utf-8 -*-
#Variables
import socket, os
host = "1.0.0.0"
port = 8000
obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
obj.setblocking(0)
obj.connect((host, port))
name_host_server = socket.gethostname()
print("[+] conexion establecida")
while True:
   mens = raw_input("3[1;31m"+host+"3[1;32m"+"@"+name_host_server+":"+"3[0;37m"+"$ ")
   if mens == "close":
      os.system("fuser -k -n tcp %s" % port)
      break
      #Con el metodo send, enviamos el mensaje
   obj.send(mens)
   data = obj.recv(1024)
   print(data)
   #Cerramos la instancia del objeto servidor
obj.close()

#Imprimimos la palabra Adios para cuando se cierre la conexion
print("Conexion cerrada")
    
asked by cat_12 02.01.2019 в 20:09
source

0 answers