fix: udp handling and ipv4 and ipv6 filtering
This commit is contained in:
22
cmd/stats.go
22
cmd/stats.go
@@ -44,6 +44,10 @@ var (
|
||||
statsInterval time.Duration
|
||||
statsCount int
|
||||
statsNoHeaders bool
|
||||
statsTCP bool
|
||||
statsUDP bool
|
||||
statsListen bool
|
||||
statsEstab bool
|
||||
)
|
||||
|
||||
var statsCmd = &cobra.Command{
|
||||
@@ -70,6 +74,18 @@ func runStatsCommand(args []string) {
|
||||
filters.IPv4 = ipv4
|
||||
filters.IPv6 = ipv6
|
||||
|
||||
// apply shortcut flags
|
||||
if statsTCP && !statsUDP {
|
||||
filters.Proto = "tcp"
|
||||
} else if statsUDP && !statsTCP {
|
||||
filters.Proto = "udp"
|
||||
}
|
||||
if statsListen && !statsEstab {
|
||||
filters.State = "LISTEN"
|
||||
} else if statsEstab && !statsListen {
|
||||
filters.State = "ESTABLISHED"
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -297,4 +313,10 @@ func init() {
|
||||
statsCmd.Flags().BoolVar(&statsNoHeaders, "no-headers", false, "Omit headers for table/csv output")
|
||||
statsCmd.Flags().BoolVarP(&ipv4, "ipv4", "4", false, "Only show IPv4 connections")
|
||||
statsCmd.Flags().BoolVarP(&ipv6, "ipv6", "6", false, "Only show IPv6 connections")
|
||||
|
||||
// shortcut filters
|
||||
statsCmd.Flags().BoolVarP(&statsTCP, "tcp", "t", false, "Show only TCP connections")
|
||||
statsCmd.Flags().BoolVarP(&statsUDP, "udp", "u", false, "Show only UDP connections")
|
||||
statsCmd.Flags().BoolVarP(&statsListen, "listen", "l", false, "Show only listening sockets")
|
||||
statsCmd.Flags().BoolVarP(&statsEstab, "established", "e", false, "Show only established connections")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user