36 lines
608 B
Go
36 lines
608 B
Go
|
package dns
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"testing"
|
||
|
|
||
|
"git.loafle.net/overflow/overflow_discovery/service/matcher"
|
||
|
)
|
||
|
|
||
|
func TestDns(t *testing.T) {
|
||
|
m := NewMatcher()
|
||
|
info := matcher.NewMatchInfo("168.126.63.1", 53)
|
||
|
|
||
|
conn, _ := net.Dial("udp", "168.126.63.1:53")
|
||
|
|
||
|
defer conn.Close()
|
||
|
|
||
|
for i := 0; i < m.PacketCount(); i++ {
|
||
|
if m.IsSend(info) != true {
|
||
|
t.Error("not port")
|
||
|
}
|
||
|
pack := m.Packet(i)
|
||
|
conn.Write(pack.Buffer)
|
||
|
bytes := make([]byte, 1024)
|
||
|
n, _ := conn.Read(bytes)
|
||
|
p := matcher.NewPacket(bytes, n)
|
||
|
|
||
|
if m.Match(info, i, p) {
|
||
|
t.Log("dns found")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
t.Error("dns not found")
|
||
|
}
|
||
|
}
|