Skip to content

Commit a9777ed

Browse files
author
rex_a
committed
netstat when you cannot
netstat when you cannot
1 parent 0880851 commit a9777ed

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

embNetstat.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
#
3+
# "embedded-device netstat"
4+
#
5+
# embNetstat.sh
6+
# watered-down version of netstat for when
7+
# netstat, lsof, etc are not available
8+
#
9+
# ./embNetstat.sh [tcp | udp]
10+
#
11+
# giving credit where credit is due, i adopted this from andreisid. he has good milk:
12+
# https://www.commandlinefu.com/commands/view/15313/check-open-ports-without-netstat-or-lsof
13+
# https://www.commandlinefu.com/commands/by/andreisid
14+
#
15+
# **************
16+
# * escollapse *
17+
# * CISSP, PT+ *
18+
# * 20200204 *
19+
# **************
20+
#
21+
22+
case "$1" in
23+
"tcp")
24+
echo "Open TCP Ports:"
25+
declare -a array=($(tail -n +2 /proc/net/$1 | cut -d':' -f3 | cut -d' ' -f1))\
26+
&& ((for port in ${array[@]}; do echo $((0x$port)); done) | sort -n)
27+
;;
28+
"udp")
29+
echo "Open UDP Ports:"
30+
declare -a array=($(tail -n +2 /proc/net/$1 | cut -d':' -f3 | cut -d' ' -f1))\
31+
&& ((for port in ${array[@]}; do echo $((0x$port)); done) | sort -n)
32+
;;
33+
*)
34+
echo "Usage: $0 [tcp | udp]"
35+
;;
36+
esac

0 commit comments

Comments
 (0)