From 383c4091eee7e9192b9217f3e439d1693203030b Mon Sep 17 00:00:00 2001 From: Mike Kazantsev Date: Thu, 3 Oct 2024 11:21:04 +0500 Subject: [PATCH] lsx: simplify/compress main() loops --- README.md | 10 ++++++++++ lsx | 11 +++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b2cbc20..b604a8c 100644 --- a/README.md +++ b/README.md @@ -2392,12 +2392,22 @@ asks for fido2 touch-check unexpectedly. Has more human-readable `-p/--pretty` mode and more traditional disaggregated `-c/--conns` mode for listing specific connections instead of just processes. +See ["List connected processes for unix sockets" blog post] for some usage examples. + +["List connected processes for unix sockets" blog post]: + https://blog.fraggod.net/2024/08/06/list-connected-processes-for-unix-sockets-on-linux.html + ##### [tcpdump-translate](tcpdump-translate) Wrapper script for running `tcpdump -ln` (unbuffered lines, no dns), to translate, color-highlight and optionally filter-by specified addresses and network prefixes. +There are couple images showing what it does in ["Adding color to tcpdump" blog post]. + +["Adding color to tcpdump" blog post]: + https://blog.fraggod.net/2024/09/30/adding-color-to-tcpdump-makes-a-ton-of-difference.html + Intended use is to match known hosts or networks in the output, while leaving all other addresses intact, without going to DNS PTR records or anything like that. diff --git a/lsx b/lsx index 0f6c0f7..d52837a 100755 --- a/lsx +++ b/lsx @@ -121,17 +121,12 @@ def main(argv=None): sys.stdout.write(p) paths = list(pl.Path(p) for p in opts.paths) - if opts.adjacent: - ps = list_adjacent(paths, opts.adjacent, opts.files) - for p in ps: _pp(p) - + for p in list_adjacent(paths, opts.adjacent, opts.files): _pp(p) else: # no options - print filtered input paths back for p in paths: - if p.exists(): - if opts.files and not p.is_file(): continue - _pp(p) - else: p_err(f'path inaccessible [ {p} ]') + if not p.exists(): p_err(f'path inaccessible [ {p} ]'); continue + if not opts.files or p.is_file(): _pp(p) if __name__ == '__main__': try: sys.exit(main())