Skip to content

Commit 4a1eee2

Browse files
authored
Merge pull request #5 from Nitr4x/develop
Fixing go routine
2 parents 3b992a2 + 42953f3 commit 4a1eee2

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

bin/orfinder

69 Bytes
Binary file not shown.

engine/scanner/scanner.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"log"
66
"net"
7-
"sync"
87
"time"
98

109
"github.com/fatih/color"
@@ -108,9 +107,9 @@ func inc(ip net.IP) {
108107
}
109108
}
110109

111-
// Function Scan(address string, wg *sync.WaitGroup)
110+
// Function Scan(address string)
112111
// Perform SYN scanning on a given IP range
113-
func Scan(address string, wg *sync.WaitGroup) {
112+
func Scan(address string) {
114113
ip, ipnet, err := net.ParseCIDR(address)
115114
if err != nil {
116115
log.Fatal(err)
@@ -127,6 +126,4 @@ func Scan(address string, wg *sync.WaitGroup) {
127126
}
128127
}
129128
}
130-
131-
wg.Done()
132129
}

main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,23 @@ func main() {
3434

3535
country := parser.Parse()
3636
IPs := loader.Load(country)
37+
tasks := make(chan string)
3738

38-
for i := len(IPs) - 1; i >= 0; i-- {
39+
for i := 0; i < 100; i++ {
3940
wg.Add(1)
40-
go scanner.Scan(IPs[i], &wg)
41+
go func() {
42+
for task := range tasks {
43+
scanner.Scan(task)
44+
}
45+
wg.Done()
46+
}()
4147
}
4248

49+
for i := len(IPs) - 1; i >= 0; i-- {
50+
tasks <- IPs[i]
51+
}
52+
53+
close(tasks)
54+
4355
wg.Wait()
4456
}

0 commit comments

Comments
 (0)