From 73b88be036da8a259d6162bb86255e539daac643 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 22 Sep 2021 13:26:40 +0000 Subject: [PATCH] show ip bits --- socket-sniff.lsp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/socket-sniff.lsp b/socket-sniff.lsp index 980abe0..f056d2e 100755 --- a/socket-sniff.lsp +++ b/socket-sniff.lsp @@ -46,6 +46,10 @@ (context MAIN) +(define (ipbits IP) + (join (map (fn (X) (-8 (string "0000000" (bits X)))) + (map int (parse IP "."))))) + (setf IFACE (main-args -1) FD (LIBC6:raw-socket) ) (when (< FD) @@ -71,17 +75,17 @@ (let ((IP (LN 0)) (N (LN 1))) (TOT IP (+ (or (TOT IP) 0) N)) (TOT IP (max 0 (- (or (TOT IP) 0) 10000))) - (push (list IP (TOT IP) (TBL IP)) OUT -1) + (push (list (ipbits IP) IP (TOT IP) (TBL IP)) OUT -1) (TBL IP 0))) (sort OUT (fn (x y) - (and (> (x 1)) - (if (> (x 2)) (or (= (y 2)) (> (x 1) (y 1))) - (= (y 1)) true - (= (y 2)) (> (x 1) (y 1)))))) + (and (> (x -2)) + (if (> (x -1)) (or (= (y -1)) (> (x -2) (y -2))) + (= (y -2)) true + (= (y -1)) (> (x -2) (y -2)))))) (dotimes (i 30) (! "tput el") (when (setf x (pop OUT)) - (unless (> (x 1)) (setf x nil))) + (unless (> (x -2)) (setf x nil))) (println (or x ""))))))) (! "clear") -- 2.39.2