Lesson A3: Python for Ethical Hackers

Python is widely used for automation, testing, and lab exercises. This lesson teaches practical scripts for ethical hacking labs.

Example 1: Port Scanner

import socket

target = "127.0.0.1"
for port in range(20, 30):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    result = s.connect_ex((target, port))
    if result == 0:
        print(f"Port {port} is open")
    s.close()

Example 2: Simple Password Tester

passwords = ["1234","password","admin"]
for p in passwords:
    if p == "admin":
        print("Found password!")
Only run scripts in your labs. Do not attack real systems.

Advanced Lesson 3 of 5