Skip to content

SH4RWIN/python-nmap-network-scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Python Network Scanner

This project provides a simple yet powerful Python script for network host discovery and port scanning, leveraging the python-nmap library. It offers a menu-driven interface to perform various scanning operations on specified network ranges or individual IP addresses.

Features

This script integrates core Nmap functionalities through python-nmap, offering the following capabilities:

  • CIDR Network Device Discovery:
    • Scans a given network range (e.g., 192.168.1.0/24) using Nmap's efficient ping scan (-sn) to identify active hosts.
    • Quickly provides a list of live IP addresses in the specified CIDR block.
  • Custom IP Range Host Discovery:
    • Discovers live hosts within a user-defined IP range (e.g., 192.168.1.1-254).
    • Also uses Nmap's ping scan (-sn) for fast host detection.
  • Port and Service Scanning:
    • Performs a detailed scan on a target IP address for a specified range of TCP ports.
    • Utilizes SYN stealth scan (-sS) for efficiency and service version detection (-sV) to identify applications and their versions running on open ports.

Prerequisites

Before running this script, ensure you have the following installed:

  1. Nmap: The network scanning engine itself.
    • Linux (Debian/Ubuntu):
      sudo apt-get update
      sudo apt-get install nmap

    • Windows/macOS: Download the installer from the official Nmap website. Ensure Nmap is added to your system's PATH.

  2. Python 3: This script is written in Python 3.

Installation

Follow these steps to set up the project and install necessary Python libraries:

  1. Clone the Repository (if applicable) or Save the Script:
    Save the provided Python code as network_scanner.py (or any other .py name you prefer) in a new directory.

  2. Create a Python Virtual Environment (Recommended):
    A virtual environment ensures that the project's dependencies don't conflict with other Python projects on your system.
    # Navigate to your project directory
    cd your_project_directory

    # Create a virtual environment named 'venv'
    python3 -m venv venv

  3. Activate the Virtual Environment:

    • On Linux/macOS:
      source venv/bin/activate

    • On Windows (Command Prompt):
      venv\Scripts\activate.bat

    • On Windows (PowerShell):
      .\venv\Scripts\Activate.ps1

(You will see (venv) in your terminal prompt, indicating the virtual environment is active.)

  1. Install the python-nmap Library:
    With your virtual environment active, install the required library:
    pip install python-nmap

Usage

Once the prerequisites are met and the virtual environment is set up, you can run the script:

  1. Activate your virtual environment (if not already active, see step 3 in Installation).
  2. Run the script:
    python network_scanner.py

The script will present a menu:

--- Python Network Scanner ---
1. Discover devices in a network (CIDR Ping Scan)
2. Discover devices in a custom IP range (e.g., 192.168.1.1-254)
3. Scan ports and detect services on a specific IP address
4. Exit
Enter your choice (1, 2, 3, or 4):

Follow the prompts to enter target IP ranges or specific IP addresses and port ranges.

Important Note on Permissions:
For certain Nmap scans (like SYN scans -sS used in port scanning) that require raw socket access, you might need to run the script with elevated privileges (e.g., sudo on Linux):
sudo python network_scanner.py

Always exercise caution when running scripts with sudo.

Ethical Considerations

Always ensure you have explicit permission to scan any network or device you do not own or manage. Unauthorized network scanning can be illegal and unethical, and may lead to legal consequences or network disruption. This tool is intended for educational purposes, personal network administration, or penetration testing with proper authorization.


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


🤝 Contributing

Contributions are welcome! If you have suggestions, bug reports, or want to add features, please open an issue or submit a pull request.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages