mirror of
https://github.com/40t/go-sniffer.git
synced 2025-08-09 21:16:08 +08:00
fixed tds query & format date
This commit is contained in:
@@ -1,33 +1,35 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"github.com/google/gopacket"
|
||||
"io"
|
||||
"strings"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
port int
|
||||
port int
|
||||
version string
|
||||
cmd chan string
|
||||
done chan bool
|
||||
cmd chan string
|
||||
done chan bool
|
||||
}
|
||||
|
||||
const (
|
||||
Port int = 6379
|
||||
Port int = 6379
|
||||
Version string = "0.1"
|
||||
CmdPort string = "-p"
|
||||
)
|
||||
|
||||
var redis = &Redis {
|
||||
port:Port,
|
||||
version:Version,
|
||||
var redis = &Redis{
|
||||
port: Port,
|
||||
version: Version,
|
||||
}
|
||||
|
||||
func NewInstance() *Redis{
|
||||
func NewInstance() *Redis {
|
||||
return redis
|
||||
}
|
||||
|
||||
@@ -63,35 +65,35 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
|
||||
l := string(line[1])
|
||||
cmdCount, _ = strconv.Atoi(l)
|
||||
cmd = ""
|
||||
for j := 0; j < cmdCount * 2; j++ {
|
||||
for j := 0; j < cmdCount*2; j++ {
|
||||
c, _, _ := buf.ReadLine()
|
||||
if j & 1 == 0 {
|
||||
if j&1 == 0 {
|
||||
continue
|
||||
}
|
||||
cmd += " " + string(c)
|
||||
}
|
||||
fmt.Println(cmd)
|
||||
fmt.Println(time.Now().Format("2006-01-02 15:04:05.000") + " | " + cmd)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
SetOption
|
||||
*/
|
||||
func (red *Redis) SetFlag(flg []string) {
|
||||
SetOption
|
||||
*/
|
||||
func (red *Redis) SetFlag(flg []string) {
|
||||
c := len(flg)
|
||||
if c == 0 {
|
||||
return
|
||||
}
|
||||
if c >> 1 != 1 {
|
||||
if c>>1 != 1 {
|
||||
panic("ERR : Redis num of params")
|
||||
}
|
||||
for i:=0;i<c;i=i+2 {
|
||||
for i := 0; i < c; i = i + 2 {
|
||||
key := flg[i]
|
||||
val := flg[i+1]
|
||||
|
||||
switch key {
|
||||
case CmdPort:
|
||||
port, err := strconv.Atoi(val);
|
||||
port, err := strconv.Atoi(val)
|
||||
redis.port = port
|
||||
if err != nil {
|
||||
panic("ERR : Port error")
|
||||
@@ -107,16 +109,15 @@ func (red *Redis) SetFlag(flg []string) {
|
||||
}
|
||||
|
||||
/**
|
||||
BPFFilter
|
||||
*/
|
||||
BPFFilter
|
||||
*/
|
||||
func (red *Redis) BPFFilter() string {
|
||||
return "tcp and port "+strconv.Itoa(redis.port)
|
||||
return "tcp and port " + strconv.Itoa(redis.port)
|
||||
}
|
||||
|
||||
/**
|
||||
Version
|
||||
*/
|
||||
Version
|
||||
*/
|
||||
func (red *Redis) Version() string {
|
||||
return red.version
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user