A custom implementation of the famous Nmap (Network Mapper) port scanner, developed in C as part of the 42 curriculum. This project recreates core functionality of Nmap with additional bonus features including geolocation, reverse DNS lookup, and traceroute capabilities.
- Multiple Scan Types: SYN, NULL, FIN, XMAS, ACK, and UDP scans
- Port Range Scanning: Scan individual ports or ranges (default: 1-1024, max: 1024 ports)
- IPv4 & DNS Support: Scan IP addresses or domain names
- Multi-threading: Parallel scanning with up to 250 threads for speed
- Raw Socket Programming: Low-level packet crafting and analysis
- π Geolocation: Get geographical location of target IPs
- π Reverse DNS Lookup: Resolve IP addresses to hostnames
- π Traceroute: Show number of hops to targets
- π‘ Ping Detection: Check if targets are alive before scanning
- π Detailed Results: Comprehensive port status reporting and verbose mode
- π§ Raw Socket Programming: Built from scratch using raw sockets for complete control over packet creation and transmission
- π§΅ Multi-threaded Architecture: Implemented efficient parallel scanning with up to 250 concurrent threads
- π¦ Custom Packet Crafting: Manual TCP/UDP header construction with proper checksum calculation
- π― Network Protocol Mastery: Deep understanding of TCP/IP stack, packet structures, and network scanning techniques
- π Cross-Platform Compatibility: Robust implementation working across different Linux distributions
- β‘ Performance Optimization: Rate limiting for UDP scans and efficient thread management
- π Network Analysis: Integrated packet capture and analysis using libpcap
- π‘ Bonus Integrations: Successfully integrated external APIs for geolocation and network diagnostics
- π Modular Architecture: Clean separation of concerns with dedicated modules for parsing, scanning, and output
- π‘οΈ Error Handling: Comprehensive error management and graceful failure handling
- π Memory Management: Proper resource allocation and cleanup without memory leaks
- βοΈ Configurable Options: Extensive command-line interface with multiple scanning modes and options
# Ubuntu/Debian
sudo apt install libpcap-dev libcurl4-openssl-dev libcjson-devThis program requires root privileges to create raw sockets:
sudo ./ft_nmap [options]-
Clone the repository
git clone https://github.com/jesuserr/42Cursus_ft_nmap.git cd 42Cursus_ft_nmap -
Compile the project
make
-
Clean build files (optional)
make clean # Remove object files make fclean # Remove all generated files make re # Rebuild everything
sudo ./ft_nmap [OPTIONS] --ip IP_ADDRESS
sudo ./ft_nmap [OPTIONS] --file FILE_WITH_IPS| Option | Description | Example |
|---|---|---|
--help |
Display help and exit | --help |
--ports [RANGE] |
Port range to scan (default: 1-1024, max: 1024 ports) | --ports 80-443 |
--ip ADDRESS |
Target IP or hostname | --ip scanme.nmap.org |
--file FILE |
File with target IPs (max: 5) | --file targets.txt |
--speedup [N] |
Use N parallel threads (max: 250) | --speedup 100 |
--scan [TYPES] |
Scan types (comma-separated) | --scan SYN,UDP |
--ping |
Ping targets before scanning | --ping |
--trace |
Show hops to target | --trace |
--rdns |
Reverse DNS lookup | --rdns |
--open |
Show only open ports | --open |
--geo |
Enable geolocation | --geo |
--verbose |
Verbose output | --verbose |
| Type | Description | TCP Flags |
|---|---|---|
| SYN | TCP SYN scan (stealth) | SYN |
| NULL | TCP NULL scan | None |
| FIN | TCP FIN scan | FIN |
| XMAS | TCP XMAS scan | FIN, PSH, URG |
| ACK | TCP ACK scan | ACK |
| UDP | UDP scan (1-second delay between packets to avoid flooding) | N/A |
- Default Range: If no
--portsoption is specified, scans ports 1-1024 - Custom Range: Use
--ports 80-443to scan a range of ports - Limitations: Maximum of 1024 ports can be scanned in a single run
# Simple SYN scan on default ports (1-1024)
sudo ./ft_nmap --ip scanme.nmap.org --scan SYN
# Equivalent to -> sudo nmap scanme.nmap.org -sS -p 1-1024
# Multi-threaded SYN,XMAS,ACK scan on custom range
sudo ./ft_nmap --ip scanme.nmap.org --speedup 70 --ports 20-90 --scan SYN,ACK,XMAS
# UDP scan on specific ports (with 1-second delay between packets)
sudo ./ft_nmap --ip scanme.nmap.org --ports 60-69 --scan UDP
# Equivalent to -> sudo nmap scanme.nmap.org -p 60-69 -sU# Full feature scan with geolocation
sudo ./ft_nmap --ip scanme.nmap.org --scan SYN --ping --trace --rdns --geo --verbose
# Multiple targets from file (single-threaded)
sudo ./ft_nmap --file hosts.txt --scan SYN,ACK,NULL --open
# Multiple targets from file (multi-threaded)
sudo ./ft_nmap --file hosts.txt --scan SYN,ACK,NULL --open --speedup 250 # hosts.txt
scanme.nmap.org
192.168.1.1
target003.com
target004.com
target005.com
ft_nmap/
βββ libft/ # Custom C library with utility functions
βββ srcs/ # Source code
β βββ ft_nmap.h # Main header with structures and prototypes
β βββ main.c # Entry point and program flow
β βββ parser.c # Command-line argument parsing
β βββ parser_utils.c # Parsing utility functions
β βββ ip_utils.c # IP address and network utilities
β βββ scan_single_thread.c # Single-threaded scanning implementation
β βββ scan_multi_thread.c # Multi-threaded scanning implementation
β βββ pcap.c # Packet capture and analysis
β βββ signals.c # Signal handling (SIGINT, SIGALRM)
β βββ bonus.c # Bonus features (ping, traceroute, geolocation)
β βββ print_errors.c # Error handling and usage display
β βββ print_results.c # Results formatting and output
βββ Makefile # Build configuration
βββ README.md # This documentation
- π§ Parser Module: Command-line argument processing
- π Network Module: IP resolution and socket management
- π‘ Scanner Module: Multi-threaded port scanning engine
- π¦ Packet Module: Raw packet crafting with libpcap
- π Bonus Module: Geolocation, DNS, and traceroute features
- Requires root privileges for raw socket access
- Some firewalls may block or detect scanning activity
- Use responsibly and only on networks you own or have permission to test
- Designed for educational purposes
This is an educational project for the 42 School curriculum. While not actively maintained for contributions, feel free to:
- Report bugs or issues
- Suggest improvements
- Fork for your own learning
- How Nmap really works // And how to catch it // Stealth scan vs TCP scan // Wireshark analysis - Deep dive into how Nmap operates internally, stealth vs TCP scanning techniques, and network traffic analysis using Wireshark
- Nmap Tutorial to find Network Vulnerabilities - Comprehensive tutorial on using Nmap to discover network vulnerabilities and security weaknesses
- Nmap Full Guide - Complete guide covering all aspects of Nmap usage, from basic scans to advanced techniques
- Nmap project - The original network discovery and security auditing utility for reference and inspiration
- Wireshark - Essential network protocol analyzer for debugging packet crafting and understanding network traffic
- tcpdump & libpcap - Official tcpdump and libpcap documentation and resources
- Using libpcap in C - Practical guide to packet capture programming with libpcap
Made with β€οΈ for the 42 School curriculum