oping

package module
v0.0.0-...-16ee065 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2018 License: GPL-3.0 Imports: 7 Imported by: 0

README

oping

GoDoc Go Report Card

A simple ICMP checker of alive hosts, based on net-icmp

Main feature - one listener for all incomming packets.

example:

package main

import (
	"fmt"
	"sync"

	"github.com/prgra/oping"
)

func main() {
	p, err := oping.New(oping.Conf{Workers: 10000})
	if err != nil {
		panic(err)
	}
	var wg sync.WaitGroup
	for y := 0; y < 255; y++ {
		for x := 0; x < 255; x++ {
			go func(x int, y int, wg *sync.WaitGroup, p *oping.Pinger) {
				wg.Add(1)
				st, err := p.Ping(fmt.Sprintf("10.128.%d.%d", y, x), 5)
				if err != nil {
					fmt.Println(err)
				}
				succes := 0
				for _, s := range st {
					if s.Recv {
						succes++
					}
				}
				if succes > 0 {
					fmt.Printf("10.128.%d.%d - %d\n", y, x, succes)
				}
				wg.Done()

			}(x, y, &wg, p)
		}
	}
	wg.Wait()
	p.Close()

}

10000 workets, ping 5 packets launch on MacBook Pro mid 2012

# go build && time sudo ./_example > alive
sudo ./_example > alive  24.90s user 23.21s system 48% cpu 1:39.61 total

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	TimeOut  time.Duration
	Interval time.Duration
	Workers  int
}

Conf config for Pinger

type Pinger

type Pinger struct {
	// contains filtered or unexported fields
}

Pinger main structure

func New

func New(c Conf) (*Pinger, error)

New return new pinger

func (*Pinger) Close

func (p *Pinger) Close()

Close ping channel and quit all workers

func (*Pinger) Ping

func (p *Pinger) Ping(ip string, cnt int) ([]Stat, error)

Ping add ping to channel queue

type Stat

type Stat struct {
	SendTime time.Time
	RecvTime time.Time
	Recv     bool
	Size     int
}

Stat one icmp statistic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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