GoPacket 实现网络数据抓包分析

声明:Linux(Ubuntu) 系统

1、导包

package main

import (
	"fmt"
	"github.com/google/gopacket"
	"github.com/google/gopacket/layers"
	"github.com/google/gopacket/pcap"
	"log"
	"net"
	"time"
)

2、查询本机设备

devices, err := pcap.FindAllDevs()
if err != nil {
    log.Fatal(err)
}

3、打印设备信息

fmt.Println("Devices found:")
index:=1
for _, d := range devices {
    fmt.Printf("\n%d———— Name:%s\n", index, d.Name)
    fmt.Println("Description: ", d.Description)
    fmt.Println("Devices addresses: ", d.Addresses)
    index++

    for _, address := range d.Ad

你可能感兴趣的:(GoPacket 实现网络数据抓包分析)