Skip to content

Commit

Permalink
fix(analyze): Filter only sockets on server ports 80, 443 and 873
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Oct 15, 2024
1 parent f5b8eb3 commit bac25cb
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,18 @@ func (a *Analyzer) handleLogItem(logItem parser.LogItem) error {
return nil
}

func filterSockTabEntry(s *netstat.SockTabEntry) bool {
switch s.LocalAddr.Port {
case 80, 443, 873:
default:
return false
}
return s.State == netstat.Established
}

func (a *Analyzer) GetActiveConns(activeConn map[netip.Prefix]int) {
// Get active connections
tabs, err := netstat.TCPSocks(func(s *netstat.SockTabEntry) bool {
return s.State == netstat.Established
})
tabs, err := netstat.TCPSocks(filterSockTabEntry)
if err != nil {
a.logger.Printf("netstat error: %v", err)
} else {
Expand All @@ -376,9 +383,7 @@ func (a *Analyzer) GetActiveConns(activeConn map[netip.Prefix]int) {
activeConn[a.IPPrefix(ip)] += 1
}
}
tabs, err = netstat.TCP6Socks(func(s *netstat.SockTabEntry) bool {
return s.State == netstat.Established
})
tabs, err = netstat.TCP6Socks(filterSockTabEntry)
if err != nil {
a.logger.Printf("netstat error: %v", err)
} else {
Expand Down

0 comments on commit bac25cb

Please sign in to comment.