Black Hat Python - Justin Seitz

by: Wise_man, 7 years ago

Last edited: 7 years ago

So I've got the book black hat pyton and as the programms are python 2.7 and learning python 3.5.  I'm trying to program the TCPserver.py but having so many errors.

import socket
import threading

# Search for ports available
bind_ip = socket.gethostname()
bind_port = 9999

server_address = (bind_ip, bind_port)

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

server.bind(server_address)

server.listen(10)

print("[*] Listening on %s: %d " % server_address)

server_connection = server


def handle_client(client_socket):

    server.connect(server_address)
    message = "--> "

    # receive the client message
    received = server.recv(4096).decode('utf-8')
    received.send(message.encode('utf-8'))

    print("[*] Received: %s" % received)

    # send back a packet
    client_socket.send("You sent me :"+received)

while True:
    client, address = server.accept()

    print("[*] Accepted connection from: %s%d" % (address[0], address[1]))

    # spin up our client thread to handle incoming data
    client_handler = threading.Thread(target=handle_client, args=(client,))
    client_handler.start()

Any help would be amazing.
p.s. Harrison I've been loving the content on youtube, was wondering if you would do tutorial videos covering the programms in the book and a networking series. Thank you.



You must be logged in to post. Please login or register an account.



I would like to eventually cover more on networking, it's a serious weak spot for me right now, and, because of that, I do not think I can be of much help here :P

-Harrison 7 years ago

You must be logged in to post. Please login or register an account.