ntPinger

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLatency

func CheckLatency(avgRtt, currentRtt time.Duration) bool

Func - Check Latency. If the AvgRTT is over 10ms and current RTT > 2 * AvgRTT -> High_Latency

func Checksum

func Checksum(data []byte) uint32

Checksum calculates the checksum for an ICMP message

func ChecksumToByte

func ChecksumToByte(csum uint32) []byte

convert Checksum to []byte

func ConstructURL

func ConstructURL(Http_scheme, DestHost, Http_path string, DestPort int) string

Construct URL

func GeneratePayloadData

func GeneratePayloadData(payLoadSize int) []byte

Func - Generate Payload Date []byte

func GetSleepTime

func GetSleepTime(PacketStatus bool, Interval int, RTT time.Duration) time.Duration

Func - Get Sleep Time

func IPSlideToString

func IPSlideToString(IPSlide []string) string

resonved IPs []string -> string

func ResolveDestHost

func ResolveDestHost(DestHost string) (DestAddr []net.IP, err error)

Func - resolveDestHost

func SetDFBit

func SetDFBit(conn *net.IPConn, df bool) error

Func - Set DF bit

Types

type InputVars

type InputVars struct {
	Type          string // Select one of these: tcp, icmp, http, dns
	Count         int    // Default is 0 which means nonstop till interruption.
	PayLoadSize   int    // Specific the payload. ICMP default payload is 24 bytes. TCP/HTTP/ICMP have no payload by default.
	Timeout       int    // default timeout is 4 seconds
	Interval      int    // Interval is the wait time between each packet send. Default is 1s.
	SourceHost    string
	DestHost      string
	DestPort      int
	Http_path     string
	Http_scheme   string
	Http_method   string
	Icmp_DF       bool // ipv4 only
	Dns_query     string
	Dns_queryType string
	Dns_Protocol  string
}

CLI Imput variables Struct

type Packet

type Packet interface {
	GetStatus() bool
	GetRtt() time.Duration
	UpdateStatistics(s Statistics)
	GetType() string
	GetSendTime() time.Time
}

Packet Interface

type PacketDNS

type PacketDNS struct {
	Type          string
	Status        bool
	Seq           int
	DestAddr      string
	DestHost      string
	SendTime      time.Time
	RTT           time.Duration
	Dns_query     string
	Dns_queryType string
	Dns_protocol  string
	Dns_response  string
	// statistics
	PacketsRecv int
	PacketsSent int
	PacketLoss  float64
	MinRtt      time.Duration
	MaxRtt      time.Duration
	AvgRtt      time.Duration
	// Status update
	AdditionalInfo string
}

PacketDNS Struct

func DnsProbing

func DnsProbing(Seq int, destHost string, Dns_query string, Dns_Protocol string, timeout int) (PacketDNS, error)

func DnsProbing

func (PacketDNS) GetRtt

func (pkt PacketDNS) GetRtt() time.Duration

func (PacketDNS) GetSendTime

func (pkt PacketDNS) GetSendTime() time.Time

func (PacketDNS) GetStatus

func (pkt PacketDNS) GetStatus() bool

func (PacketDNS) GetType

func (pkt PacketDNS) GetType() string

func (*PacketDNS) UpdateStatistics

func (pkt *PacketDNS) UpdateStatistics(s Statistics)

type PacketHTTP

type PacketHTTP struct {
	Type               string
	Status             bool
	Seq                int
	DestAddr           string
	DestHost           string
	DestPort           int
	PayLoadSize        int
	SendTime           time.Time
	RTT                time.Duration
	Http_path          string
	Http_scheme        string
	Http_response_code int
	Http_response      string
	Http_method        string
	// statistics
	PacketsRecv int
	PacketsSent int
	PacketLoss  float64
	MinRtt      time.Duration
	MaxRtt      time.Duration
	AvgRtt      time.Duration
	// Status update
	AdditionalInfo string
}

PacketHTTP Struct

func HttpProbing

func HttpProbing(Seq int, destHost string, destPort int, Http_path string, Http_scheme string, Http_method string, timeout int) (PacketHTTP, error)

HttpProbing performs HTTP probing with the ability to choose HTTP methods and ignore certificate errors

func (PacketHTTP) GetRtt

func (pkt PacketHTTP) GetRtt() time.Duration

func (PacketHTTP) GetSendTime

func (pkt PacketHTTP) GetSendTime() time.Time

func (PacketHTTP) GetStatus

func (pkt PacketHTTP) GetStatus() bool

func (PacketHTTP) GetType

func (pkt PacketHTTP) GetType() string

func (*PacketHTTP) UpdateStatistics

func (pkt *PacketHTTP) UpdateStatistics(s Statistics)

type PacketICMP

type PacketICMP struct {
	Type        string
	Status      bool
	Seq         int
	DestAddr    string
	DestHost    string
	PayLoadSize int
	SendTime    time.Time
	RTT         time.Duration
	Icmp_DF     bool
	// statistics
	PacketsRecv int
	PacketsSent int
	PacketLoss  float64
	MinRtt      time.Duration
	MaxRtt      time.Duration
	AvgRtt      time.Duration
	// Status update
	AdditionalInfo string
}

PacketICMP Struct

func IcmpProbing

func IcmpProbing(Seq int, destAddr string, desetHost string, PayLoadSize int, Icmp_DF bool, timeout int, payload []byte) (PacketICMP, error)

func: IcmpProbing

func (PacketICMP) GetRtt

func (pkt PacketICMP) GetRtt() time.Duration

func (PacketICMP) GetSendTime

func (pkt PacketICMP) GetSendTime() time.Time

func (PacketICMP) GetStatus

func (pkt PacketICMP) GetStatus() bool

func (PacketICMP) GetType

func (pkt PacketICMP) GetType() string

func (*PacketICMP) UpdateStatistics

func (pkt *PacketICMP) UpdateStatistics(s Statistics)

type PacketTCP

type PacketTCP struct {
	Type        string
	Status      bool
	Seq         int
	DestAddr    string
	DestHost    string
	DestPort    int
	PayLoadSize int
	SendTime    time.Time
	RTT         time.Duration
	// statistics
	PacketsRecv int
	PacketsSent int
	PacketLoss  float64
	MinRtt      time.Duration
	MaxRtt      time.Duration
	AvgRtt      time.Duration
	// Status update
	AdditionalInfo string
}

PacketTCP Struct

func TcpProbing added in v1.0.1

func TcpProbing(ctx *context.Context, Seq int, destAddr string, desetHost string, destPort int, PayLoadSize int) (PacketTCP, error)

func: tcpProbing

func (PacketTCP) GetRtt

func (pkt PacketTCP) GetRtt() time.Duration

func (PacketTCP) GetSendTime

func (pkt PacketTCP) GetSendTime() time.Time

func (PacketTCP) GetStatus

func (pkt PacketTCP) GetStatus() bool

func (PacketTCP) GetType

func (pkt PacketTCP) GetType() string

func (*PacketTCP) UpdateStatistics

func (pkt *PacketTCP) UpdateStatistics(s Statistics)

type Pinger

type Pinger struct {

	// ************** General Fields **********************
	// Input Vars
	InputVars InputVars

	// statistics
	Stat Statistics

	// statistics Mutex
	StatsMu sync.RWMutex

	// source IP details
	SourceAddr   string
	SourceIpAddr net.IP

	// destination IP details
	DestAddr   string
	DestIpAddr net.IP

	// OnSend is called when Pinger sends a packet (for future use only)
	OnSend func(Packet)

	// OnRecv is called when Pinger receives and processes a packet (for future use only)
	OnRecv func(Packet)

	// probeChan
	ProbeChan chan Packet
}

Pinger Struct

func NewPinger

func NewPinger(InputVars InputVars) (*Pinger, error)

New returns a new Pinger struct pointer.

func (*Pinger) Resolve

func (p *Pinger) Resolve() error

Method (Pinger) - Resolve does the DNS lookup for the Pinger address and sets IP protocol.

func (*Pinger) Run

func (p *Pinger) Run(errChan chan<- error)

Method (Pinger) - Update pinger statistics

func (*Pinger) UpdateStatistics

func (p *Pinger) UpdateStatistics(pkt Packet)

Method (Pinger) - Update pinger statistics

type Statistics

type Statistics struct {
	// PacketsRecv is the number of packets received.
	PacketsRecv int

	// PacketsSent is the number of packets sent.
	PacketsSent int

	// PacketLoss is the percentage of packets lost.
	PacketLoss float64

	// MinRtt is the minimum round-trip time sent via this pinger.
	MinRtt time.Duration

	// MaxRtt is the maximum round-trip time sent via this pinger.
	MaxRtt time.Duration

	// AvgRtt is the average round-trip time sent via this pinger.
	AvgRtt time.Duration
}

Statistics represent the stats of a currently running or finished pinger operation.

func (*Statistics) UpdatePacketLoss

func (s *Statistics) UpdatePacketLoss()

Method (Statistics) - Update PacketLoss

Jump to

Keyboard shortcuts

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