arping

package module
v1.0.1-0...-3425030 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: MIT Imports: 12 Imported by: 0

README

pkg.go.dev

arping

arping is a native go library to ping a host per arp datagram, or query a host mac address

The currently supported platforms are: Linux and BSD.

Usage

arping library
  • import this library per import "github.com/j-keck/arping"
  • export GOPATH if not already (export GOPATH=$PWD)
  • download the library go get
  • run it sudo -E go run <YOUR PROGRAMM>
  • or build it go build

The library requires raw socket access. So it must run as root, or with appropriate capabilities under linux: sudo setcap cap_net_raw+ep <BIN>.

For api doc and examples see: godoc or check the standalone under 'cmd/arping/main.go'.

arping executable

To get a runnable pinger use go get -u github.com/j-keck/arping/cmd/arping. This will build the binary in $GOPATH/bin.

arping requires raw socket access. So it must run as root, or with appropriate capabilities under Linux: sudo setcap cap_net_raw+ep <ARPING_PATH>.

Documentation

Overview

Package arping is a native go library to ping a host per arp datagram, or query a host mac address

The currently supported platforms are: Linux and BSD.

The library requires raw socket access. So it must run as root, or with appropriate capabilities under linux: `sudo setcap cap_net_raw+ep <BIN>`.

Examples:

ping a host:
------------
  package main
  import ("fmt"; "github.com/j-keck/arping"; "net")

  func main(){
    dstIP := net.ParseIP("192.168.1.1")
    if hwAddr, duration, err := arping.Ping(dstIP); err != nil {
      fmt.Println(err)
    } else {
      fmt.Printf("%s (%s) %d usec\n", dstIP, hwAddr, duration/1000)
    }
  }

resolve mac address:
--------------------
  package main
  import ("fmt"; "github.com/j-keck/arping"; "net")

  func main(){
    dstIP := net.ParseIP("192.168.1.1")
    if hwAddr, _, err := arping.Ping(dstIP); err != nil {
      fmt.Println(err)
    } else {
      fmt.Printf("%s is at %s\n", dstIP, hwAddr)
    }
  }

check if host is online:
------------------------
  package main
  import ("fmt"; "github.com/j-keck/arping"; "net")

  func main(){
    dstIP := net.ParseIP("192.168.1.1")
    _, _, err := arping.Ping(dstIP)
    if err == arping.ErrTimeout {
      fmt.Println("offline")
    }else if err != nil {
      fmt.Println(err.Error())
    }else{
      fmt.Println("online")
    }
  }

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout error
	ErrTimeout = errors.New("timeout")
	ErrSize    = errors.New("truncated")
)

Functions

func EnableVerboseLog

func EnableVerboseLog()

EnableVerboseLog enables verbose logging on stdout

func FD_SET

func FD_SET(p *syscall.FdSet, i int)

func PingOverIface

func PingOverIface(dstIP net.IP, iface netlink.Link, srcIP net.IP) (hwAddr net.HardwareAddr, duration time.Duration, err error)

PingOverIface sends an arp ping over interface 'iface' to 'dstIP' from 'srcIP'

func SetTimeout

func SetTimeout(t time.Duration)

SetTimeout sets ping timeout

Types

type PingResult

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

Jump to

Keyboard shortcuts

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