Skip to content

监听网卡流量, 过滤并组装HTTP请求和响应, 供旁路分析, 抓包等用途

License

Notifications You must be signed in to change notification settings

shixiaofeia/gopacket-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gopacket-http

GitHub GitHub last commit GitHub Repo stars

监听网卡流量, 过滤并组装HTTP请求和响应, 供旁路分析, 抓包等用途

参考项目 netgraph

使用

  1. 安装libpcap-dev 和 gcc
# Ubuntu
sudo apt install -y libpcap-dev gcc

# CentOS
sudo yum install -y libpcap-devel gcc

# MacOS(Homebrew)
brew install libpcap
  1. 安装gopacket-http
go get -u github.com/shixiaofeia/gopacket-http
  1. 在代码中导入
import "github.com/shixiaofeia/gopacket-http/packet"

快速开始

package main

import (
	"context"
	"github.com/shixiaofeia/gopacket-http/packet"
	"log"
)

var eventCh = make(chan interface{}, 1024)

func main() {
	go handle()
	if err := packet.NewPacketHandle(context.Background(), "en0", eventCh).Listen(); err != nil {
		log.Println(err.Error())
	}
}

func handle() {
	for i := range eventCh {
		data := i.(packet.Event)
		log.Printf("request uri: %s, response status: %v", data.Req.RequestURI, data.Resp.Status)
	}
}

About

监听网卡流量, 过滤并组装HTTP请求和响应, 供旁路分析, 抓包等用途

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages