mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-08-11 19:24:45 +08:00
Initial commit
This commit is contained in:
40
capture/util.go
Normal file
40
capture/util.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package capture
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getLocalIPAddr() (ipAddr string, err error) {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
addrStr := addr.String()
|
||||
if strings.Contains(addrStr, "127.0.0.1") ||
|
||||
strings.Contains(addrStr, "::1") ||
|
||||
strings.Contains(addrStr, "/64") {
|
||||
continue
|
||||
}
|
||||
|
||||
addrStr = strings.TrimRight(addrStr, "1234567890")
|
||||
addrStr = strings.TrimRight(addrStr, "/")
|
||||
if len(addrStr) < 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
ipAddr = addrStr
|
||||
return
|
||||
}
|
||||
|
||||
err = fmt.Errorf("no valid ip address found")
|
||||
return
|
||||
}
|
||||
|
||||
func spliceSessionKey(srcIP string, srcPort int) (sessionKey string) {
|
||||
sessionKey = fmt.Sprintf("%s:%d", srcIP, srcPort)
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user