-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (32 loc) · 881 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"net"
"os"
"time"
"github.com/remeh/sizedwaitgroup"
)
var swg = sizedwaitgroup.New(25) // 25 Being the amount of conncurent tasks allowed to run
var ip string
func main() {
fmt.Println("Concurrent Port Scanner")
fmt.Print("Enter Ip Address: ")
fmt.Scan(&ip)
for port := 1; port < 65535; port++ { // Full amount of scanable ports
swg.Add()
go ScanPorts(ip, port) // Go routine starts here
}
swg.Wait() // Wait for all go routines to finish executing
fmt.Println("All ports have been scanned!")
os.Exit(0)
}
func ScanPorts(ip string, port int) {
strf := fmt.Sprintf("%s:%d", ip, port)
_, err := net.DialTimeout("tcp", strf, 10*time.Millisecond)
if err != nil {
//fmt.Printf("- Port %d is closed \n", port)
} else {
fmt.Printf("- Port %d is open \n", port)
}
defer swg.Done() // Calls when all routines are called
}