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 ¶
- Variables
- func EnableVerboseLog()
- func GratuitousArp(srcIP net.IP) error
- func GratuitousArpOverIface(srcIP net.IP, iface net.Interface) error
- func GratuitousArpOverIfaceByName(srcIP net.IP, ifaceName string) error
- func Ping(dstIP net.IP) (net.HardwareAddr, time.Duration, error)
- func PingOverIface(dstIP net.IP, iface net.Interface) (net.HardwareAddr, time.Duration, error)
- func PingOverIfaceByName(dstIP net.IP, ifaceName string) (net.HardwareAddr, time.Duration, error)
- func SetTimeout(t time.Duration)
- type LinuxSocket
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTimeout error ErrTimeout = errors.New("timeout") )
Functions ¶
func GratuitousArp ¶
GratuitousArp sends an gratuitous arp from 'srcIP'
func GratuitousArpOverIface ¶
GratuitousArpOverIface sends an gratuitous arp over interface 'iface' from 'srcIP'
func GratuitousArpOverIfaceByName ¶
GratuitousArpOverIfaceByName sends an gratuitous arp over interface name 'ifaceName' from 'srcIP'
func PingOverIface ¶
PingOverIface sends an arp ping over interface 'iface' to 'dstIP'
func PingOverIfaceByName ¶
PingOverIfaceByName sends an arp ping over interface name 'ifaceName' to 'dstIP'
Types ¶
type LinuxSocket ¶ added in v1.0.2
type LinuxSocket struct {
// contains filtered or unexported fields
}