gosniff

package module
v0.0.0-...-383565c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 6 Imported by: 0

README

gosniff

Go Doc

A simple packet sniffer that makes use of gopacket.

Quick Start

Installation
go get github.com/michalis-papamichael/gosniff
Usage
package main

import (
	"fmt"
	"time"

	"github.com/michalis-papamichael/gosniff"
)

func main(){
	filter := "tcp"
	sniffer := gosniff.Sniffer{InterfaceName: nil, BpfFilterExpr: &filter,
		SnapshotLength: 1024, Duration: 500 * time.Microsecond, Promiscuous: false}

	pkts, err := sniffer.Start()
	if err != nil {
		panic(err)
	}

	go func() {
		for p := range pkts {
			// do something
			fmt.Println(p)
		}
	}()

 	<-time.After(15 * time.Second)
 	fmt.Println("Closing packet sniffer")
 	stats, _ := sniffer.Stop(true)
	fmt.Printf("\n Packets Received: %v\n", stats.PacketsReceived)
}

License

gosniff is released under the MIT License.

Documentation

Overview

This is the implementation of gosniff

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintDeviceInterfaces

func PrintDeviceInterfaces() error

Types

type Sniffer

type Sniffer struct {
	// Device interface Name
	InterfaceName *string
	// BPF expression for filtering
	BpfFilterExpr *string
	// The maximum length of the packets captured
	SnapshotLength int32
	// The duration of the sniffer were packets will be consumed
	Duration time.Duration
	// Determines whether to use Promiscuous mode
	Promiscuous bool
	// contains filtered or unexported fields
}

func (*Sniffer) GetHandle

func (s *Sniffer) GetHandle() *pcap.Handle

func (*Sniffer) Start

func (s *Sniffer) Start() (chan gopacket.Packet, error)

Starts the sniffing process.

func (*Sniffer) Stop

func (s *Sniffer) Stop(getStats bool) (*pcap.Stats, error)

Stop's the sniffing process with option of returning stats.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL