forked from lcvvvv/kscan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
Submodule gonmap
updated
from b329af to c29dbe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |