network_service_matcher/snmp/v2/snmpv2_test.go

38 lines
545 B
Go
Raw Normal View History

2017-12-04 07:27:08 +00:00
package v2
import (
"net"
"testing"
cnsm "git.loafle.net/commons_go/network_service_matcher"
)
func TestSNMP2(t *testing.T) {
m := NewMatcher()
conn, err := net.Dial("udp", "192.168.1.15:161")
if err != nil {
t.Error(err)
return
}
defer conn.Close()
for i := 0; i < m.PacketCount(); i++ {
pack := m.Packet(i)
conn.Write(pack.Buffer)
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := cnsm.NewPacket(bytes, n)
if m.Match(nil, i, p) {
t.Log("SNMP found")
return
}
t.Error("SNMP not found")
}
}