my fork/clone of BishopFox/sliver's fork of https://github.com/cakturk/go-netstat/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
forest
73fdb805ec
|
3 years ago | |
---|---|---|
LICENSE | 3 years ago | |
README.md | 3 years ago | |
go.mod | 3 years ago | |
go.sum | 3 years ago | |
netstat.go | 3 years ago | |
netstat_darwin.go | 3 years ago | |
netstat_linux.go | 3 years ago | |
netstat_types_darwin.go | 3 years ago | |
netstat_windows.go | 3 years ago | |
types_darwin.go | 3 years ago |
README.md
go-netstat / Sliver
A modified version of https://github.com/cakturk/go-netstat, modifications have been made for interoperability with the rest of Silver:
- Added Darwin support
- Data structures have been ported to protobuf
Using as a library
Godoc
Getting the package
$ go get github.com/cakturk/go-netstat/netstat
import (
"fmt"
"github.com/cakturk/go-netstat/netstat"
)
func displaySocks() error {
// UDP sockets
socks, err := netstat.UDPSocks(netstat.NoopFilter)
if err != nil {
return err
}
for _, e := range socks {
fmt.Printf("%v\n", e)
}
// TCP sockets
socks, err = netstat.TCPSocks(netstat.NoopFilter)
if err != nil {
return err
}
for _, e := range socks {
fmt.Printf("%v\n", e)
}
// get only listening TCP sockets
tabs, err = netstat.TCPSocks(func(s *netstat.SockTabEntry) bool {
return s.State == netstat.Listen
})
if err != nil {
return err
}
for _, e := range socks {
fmt.Printf("%v\n", e)
}
// list all the TCP sockets in state FIN_WAIT_1 for your HTTP server
tabs, err = netstat.TCPSocks(func(s *netstat.SockTabEntry) bool {
return s.State == netstat.FinWait1 && s.LocalAddr.Port == 80
})
// error handling, etc.
return nil
}