Last active
July 15, 2023 14:41
-
-
Save trohit/adbc5284cd65054d3f20b429eb9ba5ef to your computer and use it in GitHub Desktop.
netstat without netstat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://staaldraad.github.io/2017/12/20/netstat-without-netstat/ | |
https://unix.stackexchange.com/questions/131101/without-using-network-command-lines-in-linux-how-to-know-list-of-open-ports-and | |
# enter as root within docker | |
dr exec -it -u root:root lab bash | |
grep -v "grep -v "rem_address" /proc/net/tcp | 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 | |
} {x=hextodec(substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."hextodec(substr($2,i,2))}{print x":"hextodec(substr($2,index($2,":")+1,4))}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment