Skip to content

Instantly share code, notes, and snippets.

@canhnt
Created December 12, 2022 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canhnt/7cf1d3b1129da16baafc5c1013bf1ab1 to your computer and use it in GitHub Desktop.
Save canhnt/7cf1d3b1129da16baafc5c1013bf1ab1 to your computer and use it in GitHub Desktop.
```
awk '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}}' /proc/net/tcp
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment