Showing posts with label SSH (22). Show all posts
Showing posts with label SSH (22). Show all posts

Saturday, February 14, 2026

Modified Python Scripts for Network Audit using reportlab, python-nmap, psutil (Kali Linux)

Advanced Network Intelligence: Pro-Python Reporting | Kali Linux

Advanced Network Intelligence Report

Stepping up to a "Pro" network scanner with port discovery and interface mapping.

Evolution: We are integrating python-nmap for port discovery and psutil for interface details (MAC, gateway) to build a professional auditor.

1. Updated Script Requirements

You must install additional libraries in your Kali terminal to handle network-level data and port scanning.

  1. Update your package list and install dependencies: sudo apt update && pip3 install python-nmap psutil reportlab
Note: This script requires sudo because nmap needs root privileges for certain types of TCP scans.

2. The Python Script: Pro-Network Auditor

This version fetches local interface data and performs a TCP port scan on the hosts it finds.

import socket
import os
import psutil
import nmap
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

def get_network_interfaces():
    interfaces = []
    stats = psutil.net_if_addrs()
    for intf, addrs in stats.items():
        for addr in addrs:
            if addr.family == socket.AF_INET:
                interfaces.append({"name": intf, "ip": addr.address, "mask": addr.netmask})
    return interfaces

def scan_ports(ip):
    nm = nmap.PortScanner()
    try:
        nm.scan(ip, '21,22,80,443,3389', arguments="-T4")
        if ip in nm.all_hosts():
            open_ports = []
            for proto in nm[ip].all_protocols():
                lport = nm[ip][proto].keys()
                for port in lport:
                    if nm[ip][proto][port]['state'] == 'open':
                        open_ports.append(f"{port}({proto})")
            return ", ".join(open_ports) if open_ports else "None Found"
    except Exception:
        pass
    return "Scan Failed"
Network-Scan-PDF result

Figure: Pro-Network Intelligence PDF Report using ReportLab. (Click to enlarge)

What’s New in This Version:

  • System Interface Discovery: Uses psutil to list active cards (eth0, wlan0) for network context.
  • Integrated Port Scanner: Probes target IPs for common services like SSH (22), HTTP (80), and RDP (3389).
  • Cleaned Up PDF Layout: Improved report structure with section headers and lines.

#NmapAutomation #NetworkScanning #PythonForHacking #KaliLinuxTools #CybersecurityReporting
Generated for Kali Linux Power Users - 2026