Finally got this project working. TCP client/sever, client is set to send and recieve packets from client and server listens for incoming traffic and sends packets back.
client:
import socket
target_host = "www.google.com"
target_port = 80
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect the client
client.connect((target_host, target_port))
# send data
client.send("GET / HTTP/1.1\r\nHost: google.com\r\n\r\n")
# receive data
response = client.recv(4096)
print response
server:
import socket
import threading
bind_ip = "0.0.0.0"
bind_port = 9999
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_ip, bind_port))
server.listen(5)
print "[*] Listening on %s:%d" % (bind_ip, bind_port)
# thread for handling clients
def handle_client(client_socket):
#print out what client sends
request = client_client.recv(1024)
print "[*] Received: %s" % request
# send a packet to client
client_socket.send("ACK!")
client_socket.close()
while True:
client,addr = server.accept()
print "[*] Accepted connection from: %s:%d" % (addr[0],addr[1])
# spin client thread to handle incoming traffic
client_handler = threading.Thread(target=handle_client,args=(client,))
client_handler.start()