Docs update

This commit is contained in:
chenjiandongx 2021-11-21 20:52:32 +08:00
parent 2f5dc11dd6
commit d18bf6dbdb
4 changed files with 19 additions and 11 deletions

View File

@ -1,5 +1,9 @@
# sniffer
[![GoDoc](https://godoc.org/github.com/chenjiandongx/sniffer?status.svg)](https://godoc.org/github.com/chenjiandongx/sniffer)
[![Go Report Card](https://goreportcard.com/badge/github.com/chenjiandongx/sniffer)](https://goreportcard.com/report/github.com/chenjiandongx/sniffer)
[![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
> *A modern alternative network traffic sniffer inspired by [bandwhich](https://github.com/imsnif/bandwhich)(Rust) and [nethogs](https://github.com/raboof/nethogs)(C++).*
https://user-images.githubusercontent.com/19553554/141692419-da8b63e1-e936-4d14-8ff5-5893e20a1f27.mov

View File

@ -13,12 +13,13 @@ import (
)
type lsofConn struct {
invoker LsofInvoker
invoker lsofInvoker
}
type LsofInvoker struct{}
type lsofInvoker struct{}
func (i LsofInvoker) Exec() ([]byte, error) {
// Exec executes the command and return the output bytes of it.
func (i lsofInvoker) Exec() ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

5
dns.go
View File

@ -50,6 +50,7 @@ func (c *DNSResolver) Close() {
c.wg.Wait()
}
// Lookup resolve remote ip to the domains.
func (c *DNSResolver) Lookup(ip string) string {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
@ -62,6 +63,10 @@ func (c *DNSResolver) Lookup(ip string) string {
return ip
}
if len(addrs) == 1 {
return addrs[0]
}
sort.Strings(addrs)
return addrs[0]
}

14
ui.go
View File

@ -287,18 +287,12 @@ func (pv *PlotViewer) Shift() {
pv.shiftIdx++
width, height := termui.TerminalDimensions()
pv.grid = pv.newGrid(width, height)
if pv.count <= 1 {
return
}
termui.Render(pv.grid)
pv.render()
}
func (pv *PlotViewer) Resize(width, height int) {
pv.grid = pv.newGrid(width, height)
if pv.count <= 1 {
return
}
termui.Render(pv.grid)
pv.render()
}
func (pv *PlotViewer) Render(stats interface{}) {
@ -313,6 +307,10 @@ func (pv *PlotViewer) Render(stats interface{}) {
pv.updatePackets(data)
pv.updateBytes(data)
pv.updateConnections(data)
pv.render()
}
func (pv *PlotViewer) render() {
if pv.count <= 1 {
return
}