there have been countless times during penetration tests that 've needed to whip up tcp client to test for servicessend garbage datafuzzor any number of other tasks if you are working within the confines of large enterprise environmentsyou won' have the luxury of networking tools or compilersand sometimes you'll even be missing the absolute basics like the ability to copy/paste or an internet connection this is where being able to quickly create tcp client comes in extremely handy but enough jabbering -let' get coding here is simple tcp client import socket target_host "www google comtarget_port create socket object client socket socket(socket af_inetsocket sock_streamconnect the client client connect((target_host,target_port)send some data client send("get http/ \ \nhostgoogle com\ \ \ \ "receive some data response client recv( print response we first create socket object with the af_inet and sock_stream parameters the af_inet parameter is saying we are going to use standard ipv address or hostnameand sock_stream indicates that this will be tcp client we then connect the client to the server and send it some data the last step is to receive some data back and print out the response this is the simplest form of tcp clientbut the one you will write most often in the above code snippetwe are making some serious assumptions about sockets that you definitely want to be aware of the first assumption is that our connection will always succeedand the second is that the server is always expecting us to send data first (as opposed to servers that expect to send data to you first and await your responseour third assumption is that the server will always send us data back in timely fashion we make these assumptions largely for simplicity' sake while programmers have varied opinions about how to deal with blocking socketsexception-handling in socketsand the likeit' quite rare for pentesters to build these niceties into the quick-and-dirty tools for recon or exploitation workso we'll omit them in this