Python: Popular for Hackers

Original article was published on Artificial Intelligence on Medium

Python: Popular for Hackers

Taken from google

Python is the most popular language in today’s world. Because of its community support and lines of code. Python language used is every field like IT, Business, Aeronautical, Space research, Hacking, and etc.

In the world, people are thinking that hacking is the very scariest thing. But there are many types of hackers like

  1. White hat hackers
  2. Black hat hackers
  3. Blue hat hackers
  4. Grey hat hackers

I am not going to explain all hackers as of now. But my main point is that this all hacker’s favorite language is python. They all prefer python at first. Because it is very easy to implement the script. They make the exploits, tools, the Hacking framework, and etc. in Python. I will give you some of the tools and frameworks below. Hackers generally use several tools to access the network and use scripts to search for any anomalies or vulnerable points on the network and Python is a simple, powerful, and open-source programming language which is excellent to write scripts for Ethical Hacking.

Now I am showing you how you can create a TCP server with Python.

Creating a TCP server with Python

This is server-side:

import socketserver

class MyTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
self.data = self.request.recv(1024).strip()
print("{} wrote:".format(self.client_address[0]))
print(self.data)
self.request.sendall(self.data.upper())

if __name__ == "__main__":
HOST, PORT = "localhost", 9999
with socketserver.TCPServer((HOST, PORT), MyTCPHandler) as server:
server.serve_forever()

Cilent-Side:

import socket
import sys

HOST, PORT = "localhost", 9999
data = " ".join(sys.argv[1:])

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOST, PORT))
sock.sendall(bytes(data + "\n", "utf-8"))
received = str(sock.recv(1024), "utf-8")

print("Sent: {}".format(data))
print("Received: {}".format(received))

Running the Code:

Server-side:

You will get the packet from the client send the package on the server

Client-Side:

So This is the small script to create the TCP server.

Thank you.
Follow now, If you want good content daily.

follow me on:

Shrey Ghelani
Computer Science Student