This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
fuss:awk [2018/01/02 01:47] – [Convert Key-Value Map to JSON] office | fuss:awk [2021/03/23 02:38] – [Convert Key-Value Map to JSON] office | ||
---|---|---|---|
Line 121: | Line 121: | ||
} | } | ||
' | ' | ||
+ | </ | ||
+ | |||
+ | ====== Netstat with Awk ====== | ||
+ | |||
+ | From [[https:// | ||
+ | |||
+ | <code bash> | ||
+ | # Based on gist https:// | ||
+ | # - added TCP states | ||
+ | |||
+ | awk ' | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | states[" | ||
+ | } | ||
+ | function hextodec(str, | ||
+ | ret = 0 | ||
+ | n = length(str) | ||
+ | for (i = 1; i <= n; i++) { | ||
+ | c = tolower(substr(str, | ||
+ | k = index(" | ||
+ | ret = ret * 16 + k | ||
+ | } | ||
+ | return ret | ||
+ | } | ||
+ | function getIP(str, | ||
+ | ret=hextodec(substr(str, | ||
+ | for (i=5; i>0; i-=2) { | ||
+ | ret = ret" | ||
+ | } | ||
+ | ret = ret":" | ||
+ | return ret | ||
+ | } | ||
+ | NR > 1 {{if(NR==2)print "Local - Remote"; | ||
+ | |||
</ | </ | ||