2017-12-04 07:27:08 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"net"
|
|
|
|
"testing"
|
2017-12-04 08:16:03 +00:00
|
|
|
|
|
|
|
cnsm "git.loafle.net/commons_go/network_service_matcher"
|
2017-12-04 07:27:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHTTPMatcher_Packet(t *testing.T) {
|
|
|
|
hm := NewMatcher().(*HTTPMatcher)
|
|
|
|
fmt.Println(hm)
|
2017-12-04 08:16:03 +00:00
|
|
|
fmt.Println(hm.Packet(0))
|
2017-12-04 07:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPMatcher_Match(t *testing.T) {
|
|
|
|
fmt.Println("Match")
|
|
|
|
|
|
|
|
info := cnsm.NewMatchInfo("192.168.1.15", 38980)
|
|
|
|
|
|
|
|
hm := NewMatcher()
|
|
|
|
|
|
|
|
//port := types.NewPort("80", types.NewHost("192.168.1.103"), types.TYPE_TCP)
|
|
|
|
//
|
|
|
|
//var ipport string
|
|
|
|
//ipport = port.Host.Ip + ":" + string(port.Port)
|
|
|
|
|
|
|
|
//fmt.Println(ipport)
|
|
|
|
|
|
|
|
client, _ := net.Dial("tcp", "192.168.1.15:38980")
|
|
|
|
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
pack := hm.Packet(0)
|
|
|
|
|
|
|
|
//fmt.Println(pack)
|
|
|
|
|
|
|
|
//writer.WriteString(pack)
|
|
|
|
client.Write(pack.Buffer)
|
|
|
|
|
|
|
|
bytes := make([]byte, 512)
|
|
|
|
|
|
|
|
l, _ := client.Read(bytes)
|
|
|
|
|
|
|
|
//fmt.Println(bytes)
|
|
|
|
|
|
|
|
hm.Match(info, 0, cnsm.NewPacket(bytes, l))
|
|
|
|
|
|
|
|
}
|