Added a little more embelishment
This commit is contained in:
parent
ab0ea1e1ee
commit
9bb93ca47c
27
README.md
27
README.md
|
|
@ -1,3 +1,28 @@
|
|||
# rping
|
||||
|
||||
A GPT driven rust ping program
|
||||
rping is a simple implementation of the Internet Control Message Protocol (ICMP) ping utility. It sends a ping request to a specified IP address and prints the response time if a reply is received.
|
||||
|
||||
## Usage
|
||||
|
||||
To use rping, run the following command:
|
||||
|
||||
```cargo run --dest <destination IP address> [--request/-r <ping request>] [--data/-d <data>] [--payload/-p <payload>]```
|
||||
|
||||
|
||||
The `--dest` argument is required and specifies the destination IP address to send the ping request to. The `--request`, `--data`, and `--payload` arguments are optional and allow you to specify the ping request, data, and payload values, respectively. If these arguments are not provided, default values will be used.
|
||||
|
||||
## Example
|
||||
|
||||
To send a ping request to the IP address `192.0.2.1` with the default values, run the following command:
|
||||
|
||||
```cargo run --dest 192.0.2.1```
|
||||
|
||||
|
||||
To send a ping request to the same IP address with a custom ping request, data, and payload value, run the following command:
|
||||
|
||||
```cargo run --dest 192.0.2.1 --request 0x1234 --data 0x5678 --payload "hello world"```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
||||
|
|
|
|||
56
src/main.rs
56
src/main.rs
|
|
@ -1,9 +1,10 @@
|
|||
use core::time::Duration;
|
||||
use rand::{
|
||||
Rng,
|
||||
thread_rng,
|
||||
distributions::Alphanumeric,
|
||||
};
|
||||
// use rand::{
|
||||
// Rng,
|
||||
// thread_rng,
|
||||
// distributions::Alphanumeric,
|
||||
// };
|
||||
use std::time::Instant;
|
||||
|
||||
use std::{
|
||||
sync::Arc,
|
||||
|
|
@ -19,6 +20,7 @@ use std::os::{
|
|||
|
||||
fn main() {
|
||||
//env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
|
||||
// Parse the command line arguments.
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() == 1 || args.contains(&"--help".to_string()) {
|
||||
|
|
@ -49,21 +51,8 @@ fn main() {
|
|||
|
||||
let ping_request = ping_request.unwrap_or(0x0800); // Default ping request value
|
||||
let data = data.unwrap_or(0x0000); // Default data value
|
||||
let payload = temp_payload.unwrap_or(b"");
|
||||
// match temp_payload {
|
||||
// None => {
|
||||
// let mut rng = thread_rng();
|
||||
// payload=(0..64)
|
||||
// .map(|_| rng.sample(Alphanumeric) as char)
|
||||
// .collect::<String>()
|
||||
// .as_bytes()
|
||||
// // .unwrap_or("Couldn't generate 64 bits of entropy")
|
||||
// //b""
|
||||
// }
|
||||
// Some(p) => {
|
||||
// payload=p
|
||||
// }, // Default payload value
|
||||
// };
|
||||
let payload=temp_payload.unwrap_or(b"");
|
||||
|
||||
|
||||
// Create a UDP socket.
|
||||
let socket2_ipv4_socket = socket2::Socket::new(
|
||||
|
|
@ -123,7 +112,11 @@ fn main() {
|
|||
// Send the ping request to the specified destination IP address.
|
||||
let dest_addr = SocketAddr::new(IpAddr::V4(dest_ip), 0);
|
||||
println!("[SENDING ICMP DATA]\n");
|
||||
println!("CHECKSUM: [{:04x}]",checksum);
|
||||
println!("{}",rhexdump::hexdump(&buf));
|
||||
|
||||
// Starting the timer
|
||||
let now = Instant::now();
|
||||
let result = socket_arc.send_to(&buf, dest_addr);
|
||||
match result {
|
||||
Ok(bytes) => println!("> {} bytes sent over the socket", bytes),
|
||||
|
|
@ -143,6 +136,7 @@ fn main() {
|
|||
}
|
||||
Err(err) => panic!("Error receiving data: {}", err),
|
||||
};
|
||||
let elapsed = now.elapsed();
|
||||
|
||||
// Print the response from the destination.
|
||||
// print!("{} bytes from {}: icmp_seq={} ",
|
||||
|
|
@ -156,9 +150,11 @@ fn main() {
|
|||
|
||||
// Print the parsed response.
|
||||
println!("\n[ANALYSIS] \n");
|
||||
// println!("CHECKSUM: {:02x} {:02x}",(icmp_checksum<<8)&0x00ff, icmp_checksum&0xff);
|
||||
println!("CHECKSUM: [{:04x}]",icmp_checksum);
|
||||
println!("{}",rhexdump::hexdump(&buf));
|
||||
println!(" > {} bytes recv over the socket", bytes_recv);
|
||||
println!(" > icmp_type = {:width$} icmp_code = {:width$} icmp_checksum={:04x}", icmp_type, icmp_code, icmp_checksum, width=2);
|
||||
println!(" > {} bytes recv over the socket in {:.2} milliseconds", bytes_recv, (elapsed.as_micros() as f64)/1000.);
|
||||
println!(" > icmp_type = {:width$} icmp_code = {:width$}", icmp_type, icmp_code, width=2);
|
||||
println!(" > icmp_id = {:width$} icmp_seq = {:width$}", icmp_id, icmp_seq, width=2);
|
||||
// print!("data=");
|
||||
// for b in data {
|
||||
|
|
@ -166,3 +162,19 @@ fn main() {
|
|||
// }
|
||||
println!();
|
||||
}
|
||||
|
||||
|
||||
// match temp_payload {
|
||||
// None => {
|
||||
// let mut rng = thread_rng();
|
||||
// payload=(0..64)
|
||||
// .map(|_| rng.sample(Alphanumeric) as char)
|
||||
// .collect::<String>()
|
||||
// .as_bytes()
|
||||
// // .unwrap_or("Couldn't generate 64 bits of entropy")
|
||||
// //b""
|
||||
// }
|
||||
// Some(p) => {
|
||||
// payload=*p
|
||||
// }, // Default payload value
|
||||
// };
|
||||
Loading…
Reference in New Issue