Skip to content

lehoai/NetworkScanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetworkScanner

NetworkScanner is a C++ network scanning tool designed to discover active devices on a network and check the status of common ports.

image

✨ Features

  • 🔍 Network Scanning: Automatically detect active hosts within a subnet
  • 🚪 Port Checking: Check SSH (port 22) and HTTP (port 80) status
  • Multi-threaded: Uses async tasks for fast scanning
  • 🖥️ Cross-platform: Supports both Windows and Linux
  • ⏱️ Configurable Timeout: Adjustable timeout settings

📋 Requirements

Linux:

  • CMake 3.8+
  • GCC with C++20 support
  • GDB (for debugging)

Windows:

  • CMake 3.8+
  • Visual Studio 2019+ or MinGW
  • MSVC or GCC

🚀 Building

Build Release (Optimized):

# Using Cursor IDE
Ctrl + B

# Or using terminal
mkdir -p build/Release
cmake -B build/Release -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build/Release

Build Debug (with debug symbols):

# Using Cursor IDE: Ctrl+Shift+P -> Tasks: Run Task -> Build Debug

# Or using terminal
mkdir -p build/Debug
cmake -B build/Debug -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build/Debug

🎮 Usage

Running the program:

# Release version
./build/Release/NetworkScanner/NetworkScanner [network_prefix]

# Debug version
./build/Debug/NetworkScanner/NetworkScanner [network_prefix]

Command line options:

# Default scan (192.168.1.1-254)
./NetworkScanner

# Custom network scanning with flexible formats
./NetworkScanner 172           # Scan 172.0.0.1-254
./NetworkScanner 10.5          # Scan 10.5.0.1-254  
./NetworkScanner 192.168.1     # Scan 192.168.1.1-254
./NetworkScanner 192.168.1.    # Scan 192.168.1.1-254 (with trailing dot)

# Show help
./NetworkScanner -h
./NetworkScanner --help

Supported network prefix formats:

  • Single octet: 172 → automatically becomes 172.0.0.
  • Double octet: 10.5 → automatically becomes 10.5.0.
  • Triple octet: 192.168.1 → automatically becomes 192.168.1.
  • With trailing dot: 192.168.1. → remains 192.168.1.

Example output:

The program will scan the specified network range and display:

  • IP addresses of active devices
  • SSH port (22) status
  • HTTP port (80) status
  • Scan summary with statistics

Network validation:

  • Each octet must be between 0-255
  • Maximum 3 octets can be specified
  • Invalid formats will show helpful error messages

🐛 Debugging in Cursor IDE

Starting debug session:

  • F5 - Start debug session
  • Set breakpoints by clicking on line numbers
  • Use debug controls to step through code

Debug shortcuts:

  • F5 - Start/Continue
  • F10 - Step Over
  • F11 - Step Into
  • Shift+F11 - Step Out
  • Shift+F5 - Stop debugging

📁 Project Structure

NetworkScanner/
├── CMakeLists.txt              # Root CMake configuration
├── NetworkScanner/
│   ├── CMakeLists.txt          # Executable CMake config
│   ├── NetworkScanner.cpp      # Main application
│   ├── NetworkScanner.h        # Main header
│   ├── Scanner.cpp             # Network scanning logic
│   ├── Scanner.h               # Scanner class header
│   └── Host.h                  # Host structure definition
├── .vscode/
│   ├── tasks.json              # Build tasks
│   └── launch.json             # Debug configuration
├── build/
│   ├── Debug/                  # Debug build output
│   └── Release/                # Release build output
└── README.md                   # Project documentation

⚙️ VSCode/Cursor Configuration

The project comes pre-configured with:

  • Ctrl+B: Build Release
  • F5: Debug with GDB
  • CMake integration
  • C++ IntelliSense

🔧 Technical Details

Core Components:

  • Scanner class: Handles network scanning logic
  • Host structure: Stores device information
  • Async scanning: Multi-threaded port checking
  • Cross-platform sockets: Windows and Linux compatibility

Scanning Process:

  1. Ping sweep to detect alive hosts
  2. Parallel port scanning on discovered hosts
  3. Results sorting by IP address
  4. Clean output display

🤝 Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

Distributed under the MIT License. See LICENSE for more information.

📞 Contact

Project Link: https://github.com/yourusername/NetworkScanner


Star this repo if you find it helpful!

About

Scanning tool to discover active devices on a local network

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published