Skip to main content

parse_lsof

Function parse_lsof 

Source
pub fn parse_lsof(output: &str) -> Vec<(u16, u32, String)>
Expand description

Parses lsof -iTCP -sTCP:LISTEN -P -n output, returning (port, pid, command) triples.

use limitless_cli::modules::port_watcher::parse_lsof;
let lsof = "\
COMMAND     PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node      9921 aseem   21u  IPv4 12345      0t0  TCP *:3000 (LISTEN)
python    12345 aseem   22u  IPv6 67890      0t0  TCP [::]:8080 (LISTEN)
bash       7777 aseem    4u  IPv4 11111      0t0  TCP 127.0.0.1:5432 (LISTEN)
";
let found = parse_lsof(lsof);
assert!(found.contains(&(3000, 9921, "node".to_string())));
assert!(found.contains(&(8080, 12345, "python".to_string())));