From e067b2c21ce7b5fffdc50de94a3605ce2438503f Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 14 Dec 2017 11:22:42 +0900 Subject: [PATCH] ing --- crawler/impl/health/SocketHeahthCrawler.go | 66 +++++++++++++--------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/crawler/impl/health/SocketHeahthCrawler.go b/crawler/impl/health/SocketHeahthCrawler.go index 7ea62d1..ade7859 100644 --- a/crawler/impl/health/SocketHeahthCrawler.go +++ b/crawler/impl/health/SocketHeahthCrawler.go @@ -2,6 +2,7 @@ package health import ( "crypto/tls" + "encoding/base64" "fmt" "net" "time" @@ -70,47 +71,52 @@ func (s *SocketHeahthCrawler) CheckHeahth(config *configM.Config) (result map[st port, _ := cuej.NumberToInt(connection.Port) info := cnsm.NewMatchInfo(connection.IP, port) - if s.m.IsPrePacket() == true { - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := cnsm.NewPacket(bytes, n) - if s.m.Match(info, 0, p) == false { + if s.m.IsPrePacket() { + result["PacketType"] = "Pre" + + buf := make([]byte, 1024) + n, _ := conn.Read(buf) + p := cnsm.NewPacket(buf, n) + if !s.m.Match(info, 0, p) { + result["Packet"] = convertBase64(buf) result["Error"] = "Not Matched" return - } else { - - for i := 0; i < s.m.PacketCount(); i++ { - pack := s.m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - - if !s.m.HasResponse(i + 1) { // empty last response - break - } - - p := cnsm.NewPacket(bytes, n) - if s.m.Match(info, i+1, p) == false { - result["Error"] = "Not Matched" - return - } - } - } - } else { for i := 0; i < s.m.PacketCount(); i++ { pack := s.m.Packet(i) conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) + buf := make([]byte, 1024) + n, _ := conn.Read(buf) + + if !s.m.HasResponse(i + 1) { // empty last response + break + } + + p := cnsm.NewPacket(buf, n) + if s.m.Match(info, i+1, p) == false { + result["Packet"] = convertBase64(buf) + result["Error"] = "Not Matched" + return + } + } + + } else { + result["PacketType"] = "Post" + + for i := 0; i < s.m.PacketCount(); i++ { + pack := s.m.Packet(i) + conn.Write(pack.Buffer) + buf := make([]byte, 1024) + n, _ := conn.Read(buf) if !s.m.HasResponse(i) { // empty last response break } - p := cnsm.NewPacket(bytes, n) + p := cnsm.NewPacket(buf, n) if s.m.Match(info, i, p) == false { + result["Packet"] = convertBase64(buf) result["Error"] = "Not Matched" return } @@ -121,3 +127,7 @@ func (s *SocketHeahthCrawler) CheckHeahth(config *configM.Config) (result map[st return } + +func convertBase64(buf []byte) string { + return base64.StdEncoding.EncodeToString(buf) +}