trying a little bit of array scanning for open ports.
my code looks like below:
/bin/netstat -lntp|\
awk 'BEGIN { split("25 80 2020 6033 6010",q); }
$1 == "tcp" { split($4,a,":"); p[a[2]]++; }
$1 == "tcp6" { split($4,a,":");p[a[4]]++ }
END {
for ( i in q ) {
if (! q in p ) { printf("%s\n",q) }
}
}'
my input is:
# /bin/netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 4227/mysqld
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 5584/smbd
tcp 0 0 127.0.0.1:5900 0.0.0.0:* LISTEN 5620/kvm
tcp 0 0 127.0.0.1:5901 0.0.0.0:* LISTEN 5643/kvm
tcp 0 0 127.0.0.1:5902 0.0.0.0:* LISTEN 5672/kvm
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2347/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4482/sshd
tcp 0 0 0.0.0.0:631 0.0.0.0:* LISTEN 3513/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 4969/exim4
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 31012/3
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 5584/smbd
tcp 0 0 0.0.0.0:46787 0.0.0.0:* LISTEN 2378/rpc.statd
tcp6 0 0 :::139 :::* LISTEN 5584/smbd
tcp6 0 0 :::111 :::* LISTEN 2347/rpcbind
tcp6 0 0 :::80 :::* LISTEN 11530/apache2
tcp6 0 0 :::22 :::* LISTEN 4482/sshd
tcp6 0 0 :::631 :::* LISTEN 3513/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 4969/exim4
tcp6 0 0 ::1:6010 :::* LISTEN 31012/3
tcp6 0 0 :::443 :::* LISTEN 11530/apache2
tcp6 0 0 :::445 :::* LISTEN 5584/smbd
tcp6 0 0 :::57726 :::* LISTEN 2378/rpc.statd
#
the output I am looking for is something like
6010 port is not listed in allowed ports, the process is "31012/3" on "tcp6"
thanks