A simple traceroute utility written in Rust using the pnet
crate. This program sends ICMP Echo Request packets with increasing Time-To-Live (TTL) values to map the network path to a specified destination IP address.
- ICMP Packet Handling: Sends ICMP Echo Request packets and listens for responses.
- TTL Management: Increments the TTL value to trace each hop to the destination.
- Round-Trip Time Measurement: Calculates the time taken for each packet to reach the hop and return.
- Destination Detection: Stops tracing once the destination is reached.
- Rust: Ensure you have Rust and Cargo installed. You can install Rust using rustup.
- Administrator Privileges: Root or administrator rights are required to send raw ICMP packets.
-
Clone the Repository
git clone https://github.com/junfengyu/traceroute_rust.git cd traceroute_rust
-
Update Dependencies
Ensure that your
Cargo.toml
includes the necessary dependencies:[dependencies] pnet = "0.28.0" pnet_packet = "0.28.0" pnet_transport = "0.28.0"
Then run:
cargo update
-
Build the Project
Build the release version for optimal performance:
cargo build --release
Run the program with root privileges, specifying the destination as a command-line argument:
-
Linux/macOS:
sudo ./target/release/traceroute-rust example.com
-
Windows:
Open the Command Prompt or PowerShell as Administrator and run:
.\target\release\traceroute-rust.exe 8.8.8.8
Traceroute to 8.8.8.8
1 192.168.1.1 1.23ms
2 10.0.0.1 5.67ms
3 172.16.0.1 10.45ms
4 8.8.8.8 15.78ms
Destination reached.
This project is licensed under the MIT License.