修改icmp发包模式,更适合大规模探测。

修改报错提示,--debug时,如果10秒内没有LogSuccess的消息,每隔10秒就会打印一下当前进度
This commit is contained in:
shadow1ng 2021-02-05 16:05:44 +08:00
parent 1155ba7fab
commit 8e148c0e6e

View File

@ -53,12 +53,13 @@ func GetSys() SystemInfo {
} }
func IcmpCheck(hostslist []string) { func IcmpCheck(hostslist []string) {
TmpHosts := make(map[string]struct{})
var chanHosts = make(chan string)
conn, err := icmp.ListenPacket("ip4:icmp", "0.0.0.0") conn, err := icmp.ListenPacket("ip4:icmp", "0.0.0.0")
endflag := false endflag := false
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
var chanHosts = make(chan string)
go func() { go func() {
for { for {
if endflag == true { if endflag == true {
@ -74,7 +75,8 @@ func IcmpCheck(hostslist []string) {
go func() { go func() {
for ip := range chanHosts { for ip := range chanHosts {
if !IsContain(AliveHosts, ip) { if _, ok := TmpHosts[ip]; !ok {
TmpHosts[ip] = struct{}{}
fmt.Printf("(icmp) Target '%s' is alive\n", ip) fmt.Printf("(icmp) Target '%s' is alive\n", ip)
AliveHosts = append(AliveHosts, ip) AliveHosts = append(AliveHosts, ip)
} }
@ -84,7 +86,8 @@ func IcmpCheck(hostslist []string) {
for _, host := range hostslist { for _, host := range hostslist {
write(host, conn) write(host, conn)
} }
if len(hostslist) > 10 {
if len(hostslist) > 100 {
time.Sleep(6 * time.Second) time.Sleep(6 * time.Second)
} else { } else {
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)