Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
fuss:awk [2018/01/02 01:47] – [Convert Key-Value Map to JSON] officefuss:awk [2022/04/19 08:28] (current) – external edit 127.0.0.1
Line 121: Line 121:
     }     }
 ' '
 +</code>
 +
 +====== Netstat with Awk ======
 +
 +From [[https://gist.github.com/qistoph/1b0708c888f078c3720de6c6f9562997|qistoph]].
 +
 +<code bash>
 +# Based on gist https://gist.github.com/staaldraad/4c4c80800ce15b6bef1c1186eaa8da9f
 +# - added TCP states
 +
 +awk 'BEGIN{states["01"]="TCP_ESTABLISHED"
 +states["02"]="TCP_SYN_SENT"
 +states["03"]="TCP_SYN_RECV"
 +states["04"]="TCP_FIN_WAIT1"
 +states["05"]="TCP_FIN_WAIT2"
 +states["06"]="TCP_TIME_WAIT"
 +states["07"]="TCP_CLOSE"
 +states["08"]="TCP_CLOSE_WAIT"
 +states["09"]="TCP_LAST_ACK"
 +states["0A"]="TCP_LISTEN"
 +states["0B"]="TCP_CLOSING"
 +states["0C"]="TCP_NEW_SYN_RECV"
 +}
 +function hextodec(str,ret,n,i,k,c){
 +    ret = 0
 +    n = length(str)
 +    for (i = 1; i <= n; i++) {
 +        c = tolower(substr(str, i, 1))
 +        k = index("123456789abcdef", c)
 +        ret = ret * 16 + k
 +    }
 +    return ret
 +}
 +function getIP(str,ret){
 +    ret=hextodec(substr(str,index(str,":")-2,2));
 +    for (i=5; i>0; i-=2) {
 +        ret = ret"."hextodec(substr(str,i,2))
 +    }
 +    ret = ret":"hextodec(substr(str,index(str,":")+1,4))
 +    return ret
 +}
 +NR > 1 {{if(NR==2)print "Local - Remote";local=getIP($2);remote=getIP($3)}{print local" - "remote" "states[$4]}}' /proc/net/tcp
 +
 </code> </code>
  

fuss/awk.txt · Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.