File: get_ports

package info (click to toggle)
apf-firewall 9.7%2Brev1-5.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster
  • size: 536 kB
  • sloc: sh: 2,065; makefile: 41
file content (48 lines) | stat: -rwxr-xr-x 1,694 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
#
# APF 9.7 [apf@r-fx.org]
###
# Copyright (C) 1999-2007, R-fx Networks <proj@r-fx.org>
# Copyright (C) 2007, Ryan MacDonald <ryan@r-fx.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
###
#
tcp_ports=""
udp_ports=""
for ptcp in `netstat -napl | grep LISTEN | grep -v 127.0.0.1 | grep tcp | awk '{print$4}' | grep : | tr ':' ' ' | awk '{print$2}' | sort -n`; do
if [ "$tcp_ports" == "" ]; then
        tcp_ports="$ptcp"
else
        val=`echo $tcp_ports | grep -w $ptcp`
        if [ "$val" == "" ]; then
                tcp_ports="$tcp_ports,$ptcp"
        fi
fi
done

for pudp in `netstat -napl | grep -v 127.0.0.1 | grep udp | awk '{print$4}' | grep : | tr ':' ' ' | awk '{print$2}' | sort -n`; do
if [ "$udp_ports" == "" ]; then
        udp_ports="$pudp"
else
        val=`echo $udp_ports | grep -w $pudp`
        if [ "$val" == "" ]; then
                udp_ports="$udp_ports,$pudp"
        fi
fi
done

echo "  Listening TCP ports: $tcp_ports"
echo "  Listening UDP ports: $udp_ports"