Difference between revisions of "Script to use if netstat not available"

From wikieduonline
Jump to navigation Jump to search
(Created page with "https://staaldraad.github.io/2017/12/20/netstat-without-netstat/ <pre> #!/bin/bash awk 'function hextodec(str,ret,n,i,k,c){ ret = 0 n = length(str) for (i = 1; i...")
 
 
Line 1: Line 1:
 
https://staaldraad.github.io/2017/12/20/netstat-without-netstat/
 
https://staaldraad.github.io/2017/12/20/netstat-without-netstat/
  
<pre>
 
#!/bin/bash
 
  
awk 'function hextodec(str,ret,n,i,k,c){
+
#!/bin/bash
    ret = 0
+
    n = length(str)
+
awk 'function hextodec(str,ret,n,i,k,c){
    for (i = 1; i <= n; i++) {
+
    ret = 0
        c = tolower(substr(str, i, 1))
+
    n = length(str)
        k = index("123456789abcdef", c)
+
    for (i = 1; i <= n; i++) {
        ret = ret * 16 + k
+
        c = [[tolower]](substr(str, i, 1))
    }
+
        k = index("123456789abcdef", c)
    return ret
+
        ret = ret * 16 + k
}
+
    }
function getIP(str,ret){
+
    return ret
    ret=hextodec(substr(str,index(str,":")-2,2));
+
}
    for (i=5; i>0; i-=2) {
+
function getIP(str,ret){
        ret = ret"."hextodec(substr(str,i,2))
+
    ret=hextodec(substr(str,index(str,":")-2,2));
    }
+
    for (i=5; i>0; i-=2) {
    ret = ret":"hextodec(substr(str,index(str,":")+1,4))
+
        ret = ret"."hextodec(substr(str,i,2))
    return ret
+
    }
}
+
    ret = ret":"hextodec(substr(str,index(str,":")+1,4))
NR > 1 {{if(NR==2)print "Local - Remote";local=getIP($2);remote=getIP($3)}{print local" - "remote}}' /proc/net/tcp
+
    return ret
</pre>
+
}
 +
NR > 1 {{if(NR==2)print "Local - Remote";local=getIP($2);remote=getIP($3)}{print local" - "remote}}' /proc/net/tcp

Latest revision as of 17:17, 15 August 2022

https://staaldraad.github.io/2017/12/20/netstat-without-netstat/


#!/bin/bash 

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

Advertising: