Skip to content

Commit

Permalink
print processes running on local ports
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Feb 14, 2025
1 parent e2a3ab4 commit bbaec98
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 2 deletions.
143 changes: 141 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ phf = "0.11.3"
phf_shared = "0.11.3"
splines = "4.4.2"
clap = { version = "4.5.29", features = ["derive"] }
listeners = { git = "https://github.com/islameehassan/listeners" }

[target.'cfg(windows)'.dependencies]
gag = "1.0.0"
Expand Down
17 changes: 17 additions & 0 deletions src/networking/manage_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ pub fn modify_or_insert_in_map(
);
// determine upper layer service
service = get_service(key, traffic_direction);
// determine process
if let Some(local_port) = get_local_port(&key, traffic_direction) {
let processes = listeners::get_processes_by_port(local_port);
if let Ok(processes) = processes {
println!("Processes listening on port {local_port}:");
for process in processes {
println!("\t--> {process}");
}
}
}
};

let mut info_traffic = info_traffic_mutex
Expand Down Expand Up @@ -588,6 +598,13 @@ pub fn get_address_to_lookup(key: &AddressPortPair, traffic_direction: TrafficDi
}
}

pub fn get_local_port(key: &AddressPortPair, traffic_direction: TrafficDirection) -> Option<u16> {
match traffic_direction {
TrafficDirection::Outgoing => key.port1,
TrafficDirection::Incoming => key.port2,
}
}

#[cfg(test)]
mod tests {
use std::collections::HashSet;
Expand Down

0 comments on commit bbaec98

Please sign in to comment.