示例#1
0
func Example() {
	file := "1.pcap"
	outfile := "o.pcap"
	key := "ip.addr"

	err := golibwireshark.Init(file, outfile)
	if err != nil {
		fmt.Printf("open file failed\n")
		return
	}
	defer golibwireshark.Clean()

	var p golibwireshark.Packet

	for {
		p.GetPacket()
		if p.Edt == nil {
			break
		}

		if _, ok := p.IsKey(key); ok {
			p.WriteToFile()
		}

		p.FreePacket()
	}
}
func TestWriteToFile(t *testing.T) {
	file := "1.pcap"
	err := golibwireshark.ReOpenInputFile(file)
	if err != nil {
		t.Fatalf("%s", err)
	}

	err = golibwireshark.ReOpenOutputFile("o.pcap")
	if err != nil {
		t.Fatalf("%s", err)
	}

	var p golibwireshark.Packet

	p.GetPacket()
	if p.Edt == nil {
		fmt.Println("can't find packet")
		os.Exit(1)
	}

	err = p.WriteToFile()
	if err != nil {
		t.Errorf("%s", err)
	}

	p.FreePacket()
	golibwireshark.CloseInputFile()
	golibwireshark.CloseOutputFile()
}
func TestGetField(t *testing.T) {
	file := "1.pcap"
	err := golibwireshark.ReOpenInputFile(file)
	if err != nil {
		t.Fatalf("%s", err)
	}

	var p golibwireshark.Packet

	p.GetPacket()
	if p.Edt == nil {
		fmt.Println("can't find packet")
		os.Exit(1)
	}

	buf := make([]byte, 100, 200)
	w := bytes.NewBuffer(buf)

	if p.GetField("ip") {
		fmt.Fprintln(w, p)
	}

	p.FreePacket()
	golibwireshark.CloseInputFile()

	len := w.Len()
	wanted_len := 644
	if len != wanted_len {
		t.Fatalf("wanted: (%d), get: (%d)", wanted_len, len)
	}
}
func TestIskey(t *testing.T) {
	file := "1.pcap"
	err := golibwireshark.ReOpenInputFile(file)
	if err != nil {
		t.Fatalf("%s", err)
	}

	var p golibwireshark.Packet

	p.GetPacket()
	if p.Edt == nil {
		fmt.Println("can't find packet")
		os.Exit(1)
	}

	key := "ip.addr"
	get, _ := p.IsKey(key)

	p.FreePacket()
	golibwireshark.CloseInputFile()

	wanted := []string{"10.128.229.6", "10.128.228.50"}
	if get[0] != wanted[0] {
		t.Fatalf("wanted: (%s), get: (%s)", wanted[0], get[0])
	}
	if get[1] != wanted[1] {
		t.Fatalf("wanted: (%s), get: (%s)", wanted[1], get[1])
	}

}
示例#5
0
func main() {
	file := "../../1.pcap"
	key := "ip.addr"

	golibwireshark.Init(file, "")
	defer golibwireshark.Clean()

	var p golibwireshark.Packet

	for {
		p.GetPacket()
		if p.Edt == nil {
			break
		}

		if valueList, ok := p.IsKey(key); ok {
			for _, v := range valueList {
				fmt.Printf("[%s] %s\n", key, v)
			}
		}

		p.FreePacket()

	}
}
示例#6
0
func main() {
	file := "../../1.pcap"
	outfile := "o.pcap"

	err := golibwireshark.Init(file, outfile)
	if err != nil {
		fmt.Printf("open file failed\n")
		return
	}
	defer golibwireshark.Clean()

	//golibwireshark.PrintPacket()

	var p golibwireshark.Packet

	for {
		p.GetPacket()
		if p.Edt == nil {
			break
		}

		p.WriteToFile()

		p.FreePacket()

	}
}
示例#7
0
func main() {
	file := "../../1.pcap"

	err := golibwireshark.Init(file, "")
	if err != nil {
		fmt.Printf("open file failed\n")
		return
	}
	defer golibwireshark.Clean()

	var p golibwireshark.Packet

	for {
		p.GetPacket()
		if p.Edt == nil {
			break
		}

		fmt.Println(p)

		p.FreePacket()

	}
}