Skip to content

Commit 5ed1470

Browse files
committed
Merge branch 'master' of https://github.com/LinuxHub-Group/lmap
2 parents 7c995e8 + 9bb5967 commit 5ed1470

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/LinuxHub-Group/lmap
2+
3+
go 1.17

lmap.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515

1616
var icmp ICMP
1717

18-
var wg sync.WaitGroup
19-
2018
type ICMP struct {
2119
Type uint8
2220
Code uint8
@@ -34,20 +32,20 @@ func main() {
3432
fmt.Printf("使用方法:%s [-v] <网络号>/<CIDR>\n", os.Args[0])
3533
os.Exit(-1)
3634
}
37-
CheckIP(os.Args[1], isVerbose)
35+
CheckIP(args[0], isVerbose)
3836
}
3937

4038
func CheckIP(subnet string, isVerbose bool) {
4139
var usedIP []string
4240
var unusedIP []string
41+
checkerGroup := &sync.WaitGroup{}
4342
t := time.Now()
4443
hosts, _ := getAllHostsFromCIDR(subnet)
4544
for _, ip := range hosts {
46-
tmp := ip
4745
time.Sleep(500)
48-
wg.Add(1)
46+
checkerGroup.Add(1)
4947
go func(data string) {
50-
defer wg.Done()
48+
defer checkerGroup.Done()
5149
isUsed := ping(data)
5250
if isUsed {
5351
usedIP = append(usedIP, data)
@@ -60,9 +58,9 @@ func CheckIP(subnet string, isVerbose bool) {
6058
fmt.Println("未使用IP:", unusedIP)
6159
}
6260
}
63-
}(tmp)
61+
}(ip)
6462
}
65-
wg.Wait()
63+
checkerGroup.Wait()
6664
elapsed := time.Since(t)
6765
fmt.Println("IP扫描完成,耗时", elapsed)
6866
fmt.Println("已使用IP:", sortIPList(usedIP))
@@ -140,11 +138,7 @@ func ping(ip string) bool {
140138

141139
conn.SetReadDeadline(time.Time{})
142140

143-
if string(recvBuf[0:num]) != "" {
144-
return true
145-
}
146-
return false
147-
141+
return string(recvBuf[0:num]) != ""
148142
}
149143

150144
func CheckSum(data []byte) uint16 {

0 commit comments

Comments
 (0)