Untitled

mail@pastecode.io avatarunknown
python
2 months ago
996 B
1
Indexable
Never
import http.client
import sys

def inbound(response):
    print('[+] Awaiting response...')
    return response.read().decode()

def outbound(connection, message):
    connection.request('POST', '/', message.encode())
    response = connection.getresponse()
    return response.read().decode()

if __name__ == '__main__':
    try:
        host_ip = sys.argv[1]
        host_port = int(sys.argv[2])
        
        # Create an HTTP connection to the server
        connection = http.client.HTTPConnection(host_ip, host_port)
        
        while True:
            command = input('Enter command (exit to quit): ')
            if command == 'exit':
                break
            
            # Send command to server and get response
            response = outbound(connection, command)
            print(response)
        
        connection.close()
    except IndexError:
        print('[-] Command line argument(s) missing. Please try again.')
    except Exception as e:
        print(e)