Exemplo n.º 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()
	}
}
Exemplo n.º 2
0
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()
}
Exemplo n.º 3
0
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)
	}
}
Exemplo n.º 4
0
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])
	}

}
Exemplo n.º 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()

	}
}
Exemplo n.º 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()

	}
}
Exemplo n.º 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()

	}
}