mirror of https://github.com/40t/go-sniffer.git
Merge 65ac55fc33
into add66245ba
This commit is contained in:
commit
6a4aa7a811
|
@ -1,12 +1,14 @@
|
||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/gopacket"
|
|
||||||
"io"
|
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/gopacket"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Redis struct {
|
type Redis struct {
|
||||||
|
@ -35,7 +37,8 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
|
||||||
|
|
||||||
buf := bufio.NewReader(r)
|
buf := bufio.NewReader(r)
|
||||||
var cmd string
|
var cmd string
|
||||||
var cmdCount = 0
|
var now int64
|
||||||
|
cmdCount := 0
|
||||||
for {
|
for {
|
||||||
|
|
||||||
line, _, _ := buf.ReadLine()
|
line, _, _ := buf.ReadLine()
|
||||||
|
@ -55,14 +58,16 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Do not display
|
//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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now = time.Now().Unix()
|
||||||
|
// Record time and client address
|
||||||
|
cmd = fmt.Sprintf("%d [%s:%s]", now, net.Src().String(), transport.Src().String())
|
||||||
//run
|
//run
|
||||||
l := string(line[1])
|
l := string(line[1])
|
||||||
cmdCount, _ = strconv.Atoi(l)
|
cmdCount, _ = strconv.Atoi(l)
|
||||||
cmd = ""
|
|
||||||
for j := 0; j < cmdCount * 2; j++ {
|
for j := 0; j < cmdCount * 2; j++ {
|
||||||
c, _, _ := buf.ReadLine()
|
c, _, _ := buf.ReadLine()
|
||||||
if j & 1 == 0 {
|
if j & 1 == 0 {
|
||||||
|
@ -70,7 +75,7 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
|
||||||
}
|
}
|
||||||
cmd += " " + string(c)
|
cmd += " " + string(c)
|
||||||
}
|
}
|
||||||
fmt.Println(cmd)
|
fmt.Printf("%#v\n", cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue