Skip to content

Commit

Permalink
[*]修复在linux系统下spy模块运行异常的问题~
Browse files Browse the repository at this point in the history
  • Loading branch information
lcvvvv committed Jul 29, 2021
1 parent 1120a3a commit f668557
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/gonmap
Submodule gonmap updated from b329af to c29dbe
45 changes: 45 additions & 0 deletions lib/ping/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ping

import (
"github.com/go-ping/ping"
"kscan/lib/slog"
"os/exec"
"runtime"
"strings"
"time"
)

var linuxInit = false

func Check(ip string) bool {
p, err := ping.NewPinger(ip)
if err != nil {
slog.Debug(err.Error())
return false
}
if runtime.GOOS == "windows" {
p.SetPrivileged(true)
}
if runtime.GOOS == "linux" && linuxInit == false {
cmd := exec.Command("sysctl", "-n", "net.ipv4.ping_group_range")
buf, _ := cmd.Output() // 错误处理略
str := string(buf)
if strings.Contains(str, "2147483647") == false {
slog.Error("检测到当前操作系统为linux,Ping模块运行不正常,请执行下列命令后,再次打开此程序:\n",
"sudo sysctl -w net.ipv4.ping_group_range=\"0 2147483647\"",
)
}
linuxInit = true
}
p.Count = 2
p.Timeout = time.Second * 2
err = p.Run() // Blocks until finished.
if err != nil {
slog.Debug(err.Error())
}
s := p.Statistics()
if s.PacketsRecv > 0 {
return true
}
return false
}

0 comments on commit f668557

Please sign in to comment.