Skip to content

Commit

Permalink
remove field delimiters. colors and awk work better without them
Browse files Browse the repository at this point in the history
  • Loading branch information
mrak committed Aug 3, 2024
1 parent 7f09ed6 commit b2b2305
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/bin/nx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn process_arp(settings: &Settings, interface_name: &str, packet: &EthernetPacke
if !settings.arp {
return;
}
let iname = format!("[{}]", interface_name.purple());
let iname = interface_name.purple();
let ptype = "ARP".bold().red();
match ArpPacket::new(packet.payload()) {
Some(arp_packet) => {
Expand Down Expand Up @@ -277,7 +277,7 @@ fn process_arp(settings: &Settings, interface_name: &str, packet: &EthernetPacke
_ => "unknown",
}
.yellow();
println!("{iname} {ptype} {src_mac}{src_ip} > {dst_mac}{dst_ip} ~ {op}")
println!("{iname} {ptype} {src_mac}{src_ip} {dst_mac}{dst_ip} {op}")
}
None => println!("{iname} {ptype} {}", "Malformed packet".red()),
}
Expand Down Expand Up @@ -502,7 +502,7 @@ fn process_ipip(
if !settings.ipip {
return;
}
let iname = format!("[{}]", interface_name.purple());
let iname = interface_name.purple();
let ptype = "IPIP".bold().red();
match Ipv4Packet::new(packet) {
Some(ip_packet) => {
Expand Down Expand Up @@ -533,7 +533,7 @@ fn process_ipip(
let dst_ip = destination.to_string().blue();
let dst_ipip = format!("[{}]", ip_packet.get_destination()).dimmed().blue();
let bytes = format!("{}b", ip_packet.payload().len()).cyan();
println!("{iname} {ptype} {src_ip}{src_ipip} > {dst_ip}{dst_ipip} ~ {bytes}",);
println!("{iname} {ptype} {src_ip}{src_ipip} {dst_ip}{dst_ipip} {bytes}",);
}
None => println!("{iname} {ptype} {}", "Malformed packet".red()),
}
Expand All @@ -551,7 +551,7 @@ fn process_tcp(
if !settings.tcp {
return;
}
let iname = format!("[{}]", interface_name.purple());
let iname = interface_name.purple();
let ptype = "TCP".bold().red();
match TcpPacket::new(packet) {
Some(tcp_packet) => {
Expand All @@ -573,9 +573,7 @@ fn process_tcp(
let flags = tcp_type_from_flags(tcp_packet.get_flags()).yellow();
let seq = format!("#{}", tcp_packet.get_sequence()).dimmed().white();
let bytes = format!("{}b", tcp_packet.payload().len()).cyan();
println!(
"{iname} {ptype} {src_ip}{src_port} > {dst_ip}{dst_port} ~ {flags} {seq} {bytes}"
);
println!("{iname} {ptype} {src_ip}{src_port} {dst_ip}{dst_port} {flags} {seq} {bytes}");
if !settings.short && !tcp_packet.payload().is_empty() {
println!("{}", escape_payload(tcp_packet.payload()))
}
Expand All @@ -596,7 +594,7 @@ fn process_udp(
if !settings.udp {
return;
}
let iname = format!("[{}]", interface_name.purple());
let iname = interface_name.purple();
let ptype = "UDP".bold().red();
match UdpPacket::new(packet) {
Some(udp_packet) => {
Expand All @@ -616,7 +614,7 @@ fn process_udp(
let dst_ip = destination.to_string().blue();
let dst_port = format!(":{}", udp_packet.get_destination()).dimmed().blue();
let bytes = format!("{}b", udp_packet.payload().len()).cyan();
println!("{iname} {ptype} {src_ip}{src_port} > {dst_ip}{dst_port} ~ {bytes}");
println!("{iname} {ptype} {src_ip}{src_port} {dst_ip}{dst_port} {bytes}");
if !settings.short && !udp_packet.payload().is_empty() {
println!("{}", escape_payload(udp_packet.payload()))
}
Expand Down Expand Up @@ -648,7 +646,7 @@ fn process_icmpv6(
) {
return;
}
let iname = format!("[{}]", interface_name.purple());
let iname = interface_name.purple();
let ptype = "ICMP".bold().red();
match Icmpv6Packet::new(packet) {
Some(icmp_packet) => {
Expand Down Expand Up @@ -808,7 +806,7 @@ fn process_icmpv6(
let itype = i_type.yellow();
let idesc = i_desc.dimmed().white();
let bytes = format!("{}b", icmp_packet.payload().len()).cyan();
println!("{iname} {ptype} {src} > {dst} ~ {itype} {idesc} {bytes}",);
println!("{iname} {ptype} {src} {dst} {itype} {idesc} {bytes}",);
if !settings.short {
if let Some(d) = i_details {
println!("{}", d)
Expand All @@ -831,7 +829,7 @@ fn process_icmp(
if !settings.icmp {
return;
}
let iname = format!("[{}]", interface_name.purple());
let iname = interface_name.purple();
let ptype = "ICMP".bold().red();
if !filters_match_criteria(
&settings.filters,
Expand Down Expand Up @@ -930,7 +928,7 @@ fn process_icmp(
let itype = i_type.yellow();
let idesc = i_desc.dimmed().white();
let bytes = format!("{}b", icmp_packet.payload().len()).cyan();
println!("{iname} {ptype} {src} > {dst} ~ {itype} {idesc} {bytes}",);
println!("{iname} {ptype} {src} {dst} {itype} {idesc} {bytes}",);
if !settings.short {
if let Some(d) = i_details {
println!("{}", d)
Expand Down

0 comments on commit b2b2305

Please sign in to comment.