Skip to content

Commit 86dc7a5

Browse files
committed
Add --packet-help option
1 parent 55e7a67 commit 86dc7a5

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/args.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ const EXAMPLES_HELP: &str = "EXAMPLES:
2929
# List network interfaces
3030
arp-scan -l
3131
32+
# Launch a scan on a specific range
33+
arp-scan -i eth0 -n 10.37.3.1,10.37.4.55/24
34+
3235
# Launch a scan on WiFi interface with fake IP and stealth profile
33-
arp-scan -i wlp1s0 --source-ip 192.168.0.42 --profile stealth
36+
arp-scan -i eth0 --source-ip 192.168.0.42 --profile stealth
3437
3538
# Launch a scan on VLAN 45 with JSON output
3639
arp-scan -Q 45 -o json
@@ -158,6 +161,11 @@ pub fn build_args<'a>() -> Command<'a> {
158161
.takes_value(true).value_name("OPERATION_ID")
159162
.help("Custom ARP operation ID")
160163
)
164+
.arg(
165+
Arg::new("packet_help").long("packet-help")
166+
.takes_value(false)
167+
.help("Print details about an ARP packet")
168+
)
161169
.after_help(EXAMPLES_HELP)
162170
}
163171

@@ -199,7 +207,8 @@ pub struct ScanOptions {
199207
pub hw_addr: Option<u8>,
200208
pub proto_type: Option<EtherType>,
201209
pub proto_addr: Option<u8>,
202-
pub arp_operation: Option<ArpOperation>
210+
pub arp_operation: Option<ArpOperation>,
211+
pub packet_help: bool
203212
}
204213

205214
impl ScanOptions {
@@ -497,6 +506,8 @@ impl ScanOptions {
497506
},
498507
None => None
499508
};
509+
510+
let packet_help = matches.contains_id("packet_help");
500511

501512
Arc::new(ScanOptions {
502513
profile,
@@ -517,7 +528,8 @@ impl ScanOptions {
517528
hw_addr,
518529
proto_type,
519530
proto_addr,
520-
arp_operation
531+
arp_operation,
532+
packet_help
521533
})
522534
}
523535

@@ -531,6 +543,10 @@ impl ScanOptions {
531543
matches!(&self.vlan_id, Some(_))
532544
}
533545

546+
pub fn request_protocol_print(&self) -> bool {
547+
self.packet_help
548+
}
549+
534550
}
535551

536552

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ fn main() {
3939
// with an IPv4 address and root permissions (for crafting ARP packets).
4040

4141
let scan_options = ScanOptions::new(&matches);
42+
43+
if scan_options.request_protocol_print() {
44+
utils::print_ascii_packet();
45+
process::exit(0);
46+
}
4247

4348
if !utils::is_root_user() {
4449
eprintln!("Should run this binary as root or use --help for options");

src/utils.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ pub fn show_interfaces(interfaces: &[NetworkInterface]) {
6060
println!();
6161
}
6262

63+
pub fn print_ascii_packet() {
64+
65+
println!();
66+
println!(" 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ");
67+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
68+
println!("| Hardware type | Protocol type |");
69+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|");
70+
println!("| Hlen | Plen | Operation |");
71+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
72+
println!("| Sender HA |");
73+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
74+
println!("| Sender HA | Sender IP |");
75+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|");
76+
println!("| Sender IP | Target HA |");
77+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|");
78+
println!("| Target HA |");
79+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
80+
println!("| Target IP |");
81+
println!("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
82+
println!();
83+
println!(" - Hardware type (2 bytes), use --hw-type option to change");
84+
println!(" - Protocol type (2 bytes), use --proto-type option to change");
85+
println!();
86+
}
87+
6388
/**
6489
* Find a default network interface for scans, based on the operating system
6590
* priority and some interface technical details.

0 commit comments

Comments
 (0)