Skip to content

Commit

Permalink
lsx: simplify/compress main() loops
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-fg committed Oct 3, 2024
1 parent a7f7500 commit 383c409
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a name=hdr-tcpdump-translate></a>
##### [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.

Expand Down
11 changes: 3 additions & 8 deletions lsx
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 383c409

Please sign in to comment.