All Projects → rfyiamcool → go-netflow

rfyiamcool / go-netflow

Licence: other
go netflow, capture process in/out traffic, similar to c Nethogs.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-netflow

connect
tiny cross-platform socket API library
Stars: ✭ 46 (-68.28%)
Mutual labels:  pcap
hbase-packet-inspector
Analyzes network traffic of HBase RegionServers
Stars: ✭ 35 (-75.86%)
Mutual labels:  pcap
flow-indexer
Flow-Indexer indexes flows found in chunked log files from bro,nfdump,syslog, or pcap files
Stars: ✭ 43 (-70.34%)
Mutual labels:  pcap
dns-collector
Aggregator, analyzer, transporter and logging for your DNS logs
Stars: ✭ 58 (-60%)
Mutual labels:  pcap
wiresham
Simple TCP service mocking tool for replaying https://www.wireshark.org and http://www.tcpdump.org captured service traffic
Stars: ✭ 44 (-69.66%)
Mutual labels:  pcap
pcap-file
Crate to read and write pcap and pcapng files in RUST.
Stars: ✭ 25 (-82.76%)
Mutual labels:  pcap
pcapdj
pcapdj - dispatch pcap files
Stars: ✭ 41 (-71.72%)
Mutual labels:  pcap
mitmpcap
export mitmproxy traffic to PCAP file
Stars: ✭ 42 (-71.03%)
Mutual labels:  pcap
Red-Rabbit-V4
The Red Rabbit project is just what a hacker needs for everyday automation. Red Rabbit unlike most frameworks out there does not automate other peoples tools like the aircrack suite or the wifite framework, it rather has its own code and is raw source with over 270+ options. This framework might just be your everyday key to your workflow
Stars: ✭ 123 (-15.17%)
Mutual labels:  pcap
packet cafe
A platform built for easy-to-use automated network traffic analysis
Stars: ✭ 40 (-72.41%)
Mutual labels:  pcap
dsc
DNS Statistics Collector
Stars: ✭ 94 (-35.17%)
Mutual labels:  pcap
capture-dns
A simple program to capture and show DNS queries
Stars: ✭ 33 (-77.24%)
Mutual labels:  pcap
network-tools
Network Tools
Stars: ✭ 27 (-81.38%)
Mutual labels:  pcap
NetworkAlarm
A tool to monitor local network traffic for possible security vulnerabilities. Warns user against possible nmap scans, Nikto scans, credentials sent in-the-clear, and shellshock attacks. Currently supports live monitoring and network capture (pcap) scanning.
Stars: ✭ 17 (-88.28%)
Mutual labels:  pcap
sip3-captain-ce
SIP3 Captain (Community Edition)
Stars: ✭ 73 (-49.66%)
Mutual labels:  pcap
captcp
A open source program for TCP analysis of PCAP files
Stars: ✭ 110 (-24.14%)
Mutual labels:  pcap
termshark
A terminal UI for tshark, inspired by Wireshark
Stars: ✭ 7,368 (+4981.38%)
Mutual labels:  pcap
tcpslice
tcpslice concatenates multiple pcap files together, or extracts time slices from one or more pcap files.
Stars: ✭ 48 (-66.9%)
Mutual labels:  pcap
packiffer
lightweight cross-platform networking toolkit
Stars: ✭ 52 (-64.14%)
Mutual labels:  pcap
Werk
High-throughput / low-latency C++ application framework
Stars: ✭ 30 (-79.31%)
Mutual labels:  pcap

go-netflow

go-netflow, capture process in/out traffic, similar to c Nethogs.

使用 golang 实现进程级流量监控

refer

refer logic design link

refer nethogs source link

dep

yum install libpcap
yum install libpcap-devel

cli usage

netflow cli run:

go run cmd/main.go

stdout:

+---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+
|   PID   | NAME  |                      EXE                       | INODES | SUM IN | SUM OUT | IN RATE | OUT RATE |
+---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+
| 2256431 | Wget  | /usr/bin/wget                                  |      1 | 1.0 MB | 0 B     | 339 kB  | 0 B      |
+---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+
| 2257200 | Wrk   | /usr/bin/wrk                                   |      5 | 2.0 MB | 16 kB   | 653 kB  | 5.2 kB   |
+---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+
| 3707954 | Java  | /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java |     10 | 457 B  | 648 B   | 152 B   | 216 B    |
+---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+
| 2245136 | Wget  | /usr/bin/wget                                  |      1 | 444 kB | 0 B     | 148 kB  | 0 B      |
+---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+
| 2034103 | Nginx | /usr/sbin/nginx                                |     41 | 0 B    | 0 B     | 0 B     | 0 B      |
+---------+-------+------------------------------------------------+--------+--------+---------+---------+----------+

sdk simple usage:

package main

import (
	"encoding/json"
	"fmt"
	"time"

	"github.com/rfyiamcool/go-netflow"
)

func main() {
	nf, err := netflow.New(
		netflow.WithCaptureTimeout(5 * time.Second),
	)
	if err != nil {
		panic(err)
	}

	err = nf.Start()
	if err != nil {
		panic(err)
	}
	defer nf.Stop()

	<-nf.Done()

	var (
		limit     = 5
		recentSec = 5
	)

	rank, err := nf.GetProcessRank(limit, recentSec)
	if err != nil {
		panic(err)
	}

	bs, err := json.MarshalIndent(rank, "", "    ")
	if err != nil {
		panic(err)
	}

	fmt.Println(string(bs))
}

how to use sdk of go-netflow:

set pcap filename

Don't save pcap file by default.

WithStorePcap option is used to save pcap file, use tcpdump -nnr {filename} command to read pcap file.

WithStorePcap(fpath string)

set custom pcap bpf filter.

WithPcapFilter(filter string)

set custom pcap bpf filter.

example:

  • host xiaorui.cc and port 80
  • src host 123.56.223.52 and (dst port 3389 or 22)
WithPcapFilter(filter string)

limit netflow cpu/mem resource.

WithLimitCgroup(cpu float64, mem int)

set time to capturing packet.

WithCaptureTimeout(dur time.Duration)

set time to rescan process and inode data.

WithSyncInterval(dur time.Duration)

set the number of worker to consume pcap queue.

WithWorkerNum(num int)

set custom context.

WithCtx(ctx context.Context)

set custom devices to capture.

WithBindDevices(devs []string)

set pcap queue size. if the queue is full, new packet is thrown away.

WithQueueSize(size int)

types

netflow.Interface

type Interface interface {
	Start() error
	Stop()
	Done() <-chan struct{}
	LoadCounter() int64
	GetProcessRank(int, int) ([]*Process, error)
}

netflow.Process

type Process struct {
	Name         string
	Pid          string
	Exe          string
	State        string
	Inodes       []string
	TrafficStats *trafficStatsEntry
	Ring         []*trafficEntry
}

netflow.trafficStatsEntry

type trafficStatsEntry struct {
	In         int64 `json:"in"`
	Out        int64 `json:"out"`
	InRate     int64 `json:"in_rate"`
	OutRate    int64 `json:"out_rate"`
	InputEWMA  int64 `json:"input_ewma" valid:"-"`
	OutputEWMA int64 `json:"output_ewma" valid:"-"`
}

netflow.trafficEntry

type trafficEntry struct {
	Timestamp int64 `json:"timestamp"`
	In        int64 `json:"in"`
	Out       int64 `json:"out"`
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].