当前位置:网站首页>Golang system ping program to detect the surviving host (any permission)

Golang system ping program to detect the surviving host (any permission)

2020-11-08 13:42:48 Brother K8

advantage : Support arbitrary permissions , Unlike ICMP Administrator permission is required
shortcoming : Slow speed , Scan one C It's about 10 About seconds
usage : Ladon 192.168.1.1/24 PingScan

Use LadonGo
go get github.com/k8gege/LadonGo

//pingtest.go

package main
import (
	"fmt"
	"flag"
	"os"
	"github.com/k8gege/LadonGo/ping"
	)
//go run pingtest.go -host k8gege.org
var (
	host string
)

func init() {
	flag.StringVar(&host, "host", "", "IP/Host/Domain")
}

func main() {
flag.Parse()
if host == "" {
	println("Please " + os.Args[0] + " -h")
	os.Exit(0)
}

res,err := ping.CmdPing(host)
//res,err := CmdPing("k8gege.org")
if err==nil && res==true {
fmt.Println(host+" IsOnline")
}

}

版权声明
本文为[Brother K8]所创,转载请带上原文链接,感谢