Skip to content

Alice699/NetPing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 

Repository files navigation

🌐 NetPing

A cross-platform network diagnostic toolkit β€” ping, traceroute, DNS lookup, and port scanner

C++ CMake Platform License: MIT

Your own network toolkit, built from raw sockets.


Overview

NetPing is a command-line network diagnostic tool built from scratch in C++17 using raw ICMP sockets and POSIX networking APIs. It reimplements classic tools β€” ping, traceroute, nslookup, and nmap-style port scanner β€” as a learning project in low-level network programming.

Tools Included

Command Description
netping ping ICMP echo request/reply with RTT stats
netping trace Traceroute using TTL manipulation
netping dns DNS A, AAAA, MX, TXT record lookup
netping scan TCP port scanner with banner grabbing
netping whois WHOIS lookup for domains and IPs

Installation

git clone https://github.com/Alice699/netping.git
cd netping

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

# Install to /usr/local/bin (Linux/macOS)
sudo make install

Note: ping and trace require root/admin privileges (raw socket access).

Usage

Ping

$ netping ping google.com -c 5

PING google.com (142.250.185.46) 56 bytes of data.
64 bytes from 142.250.185.46: icmp_seq=1 ttl=117 time=12.4 ms
64 bytes from 142.250.185.46: icmp_seq=2 ttl=117 time=11.9 ms
64 bytes from 142.250.185.46: icmp_seq=3 ttl=117 time=12.1 ms
64 bytes from 142.250.185.46: icmp_seq=4 ttl=117 time=13.2 ms
64 bytes from 142.250.185.46: icmp_seq=5 ttl=117 time=11.8 ms

--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss
rtt min/avg/max = 11.8/12.3/13.2 ms

Traceroute

$ netping trace github.com

traceroute to github.com (140.82.121.4), 30 hops max
 1  192.168.1.1      1.2 ms    1.0 ms    1.1 ms
 2  10.0.0.1         5.4 ms    5.2 ms    5.3 ms
 3  203.0.113.1     11.2 ms   11.1 ms   11.4 ms
...
15  140.82.121.4    28.3 ms   27.9 ms   28.1 ms

Port Scanner

$ netping scan example.com -p 1-1000 --timeout 500

Scanning example.com (93.184.216.34) ports 1-1000...

PORT     STATE   SERVICE    BANNER
22/tcp   open    ssh        OpenSSH_8.9
80/tcp   open    http       nginx/1.22.1
443/tcp  open    https
8080/tcp closed

Scan complete: 4 ports scanned, 3 open, 1 closed (0.8s)

DNS Lookup

$ netping dns github.com --type ALL

DNS query for github.com
────────────────────────
A     β†’ 140.82.121.4
AAAA  β†’ (none)
MX    β†’ 10 aspmx.l.google.com
TXT   β†’ "v=spf1 ip4:192.30.252.0/22 include:_netblocks.google.com ~all"

Project Structure

netping/
β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ ping.hpp          # ICMP ping implementation
β”‚   β”œβ”€β”€ traceroute.hpp    # Traceroute via TTL
β”‚   β”œβ”€β”€ dns.hpp           # DNS resolver
β”‚   β”œβ”€β”€ scanner.hpp       # TCP port scanner
β”‚   β”œβ”€β”€ whois.hpp         # WHOIS client
β”‚   β”œβ”€β”€ socket.hpp        # RAII socket wrapper
β”‚   └── cli.hpp           # CLI argument parser
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ ping.cpp
β”‚   β”œβ”€β”€ traceroute.cpp
β”‚   β”œβ”€β”€ dns.cpp
β”‚   β”œβ”€β”€ scanner.cpp
β”‚   β”œβ”€β”€ whois.cpp
β”‚   └── main.cpp
β”œβ”€β”€ tests/
β”œβ”€β”€ CMakeLists.txt
└── README.md

Key Implementation Details

ICMP Ping: Uses SOCK_RAW with IPPROTO_ICMP. Constructs ICMP echo packets manually, calculates checksum, measures RTT with std::chrono::high_resolution_clock.

Traceroute: Sends UDP packets with incrementing TTL (1 to 30). Each router that drops the packet sends back an ICMP Time Exceeded β€” that's your hop.

Port Scanner: Attempts connect() with non-blocking socket + select() timeout. Optionally reads first 64 bytes for banner grabbing.

DNS: Manually constructs and parses DNS query packets per RFC 1035. No getaddrinfo β€” raw UDP to port 53.

What I Learned

  • Raw socket programming with ICMP and UDP
  • Manual packet construction and binary protocol parsing
  • Non-blocking I/O with select() / poll()
  • RAII wrappers for C-style resource handles
  • Cross-platform socket abstraction (POSIX vs Winsock)

Roadmap

  • IPv6 full support
  • MTU path discovery
  • Continuous monitoring mode with graph output
  • JSON output for scripting integration
  • Windows Winsock2 backend

License

MIT Β© Robbian Saputra Gumay

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors