This commit is contained in:
sola 2021-02-03 11:57:27 +08:00 committed by GitHub
commit 6a4aa7a811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -1,12 +1,14 @@
package build
import (
"github.com/google/gopacket"
"io"
"strings"
"fmt"
"strconv"
"bufio"
"fmt"
"io"
"strconv"
"strings"
"time"
"github.com/google/gopacket"
)
type Redis struct {
@ -35,7 +37,8 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
buf := bufio.NewReader(r)
var cmd string
var cmdCount = 0
var now int64
cmdCount := 0
for {
line, _, _ := buf.ReadLine()
@ -55,14 +58,16 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
}
//Do not display
if strings.EqualFold(transport.Src().String(), strconv.Itoa(red.port)) == true {
if strings.EqualFold(transport.Src().String(), strconv.Itoa(red.port)) {
continue
}
now = time.Now().Unix()
// Record time and client address
cmd = fmt.Sprintf("%d [%s:%s]", now, net.Src().String(), transport.Src().String())
//run
l := string(line[1])
cmdCount, _ = strconv.Atoi(l)
cmd = ""
for j := 0; j < cmdCount * 2; j++ {
c, _, _ := buf.ReadLine()
if j & 1 == 0 {
@ -70,7 +75,7 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
}
cmd += " " + string(c)
}
fmt.Println(cmd)
fmt.Printf("%#v\n", cmd)
}
}