Skip to content

Commit

Permalink
add stv
Browse files Browse the repository at this point in the history
  • Loading branch information
luckman212 committed Jun 7, 2022
1 parent 42683e7 commit 1ead54e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions stv
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

pfctl -vvss |
awk -v m="$1" '
BEGIN {
printf("%-14s %-8s %-4s %-26s %-24s %s\n",
"proto/dir","iface","rule","state/creator","state","talkers");
cnt=0;
}
!/^ / {
#print "recno: "NR " <== entrypoint";
rid=""; sid=""; gw=""; iface=""; talkers="";
proto=$2; st=$NF;
i=3; while (i<NF) {
talkers=sprintf("%s%s ",talkers,$i);
if($i=="->") { dir="out"; }
if($i=="<-") { dir="in"; }
i++;
}
proto_dir=sprintf("%s %s", proto, dir);
next;
}
{
#print "recno: "NR " -- not a startblock";
if($0 ~ /\+/) {
#print "recno: "NR " wscale";
next;
}
if($(NF-1)=="rule") {
#print "recno: "NR " rule";
rid=$NF;
next;
}
if($1=="id:") {
#print "recno: "NR " id";
sid=sprintf("%s/%s", $2, $4);
gw=(($6=="0.0.0.0"||$6=="::") ? "" : sprintf(" (via %s)",$6));
next;
}
if($1=="origif:") {
#print "recno: "NR " origif";
iface=$2;
}
}
{
#print "recno: "NR " output";
mm=sprintf("%%%s%%%s%%%s%%%s%%%s%%%s%%",proto_dir,iface,rid,sid,st,talkers,gw);
if(mm ~ m) {
printf "%-14s %-8s %-4s %-26s %-24s %s%s\n",
proto_dir,iface,rid,sid,st,talkers,gw;
cnt++;
}
}
END {
printf("%d state%s\n", cnt, (cnt==1 ? "":"s"));
}
'

0 comments on commit 1ead54e

Please sign in to comment.