network_service_matcher/snmp/v2/snmpv2_test.go
crusader ac4d422cd9 ing
2017-12-04 16:27:08 +09:00

38 lines
545 B
Go

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")
}
}