-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
96 lines (85 loc) · 2.2 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"sync"
"time"
)
type Host struct {
IP string
OpenPorts []NmapPortInfo
Vulns []Vulnerability
OS string
}
func generateReport(hosts []Host) {
// Generate a report of the scan results.
fmt.Println("Scanning Report")
fmt.Println("===============")
for _, host := range hosts {
fmt.Printf("IP Address: %s\n", host.IP)
fmt.Printf("Detected OS: %s\n", host.OS)
fmt.Println("Open Ports:")
for _, port := range host.OpenPorts {
fmt.Printf(" - %d/%s (%s)\n", port.Port, port.Protocol, port.Service.Name)
}
fmt.Println("Vulnerabilities:")
for _, vuln := range host.Vulns {
fmt.Printf(" - CVE: %s | Service: %s | Severity: %s | Description: %s\n", vuln.CVE, vuln.Service, vuln.Severity, vuln.Description)
}
fmt.Println("---------------")
}
}
func loadingAnimation(done chan bool) {
animationChars := []string{"-", "\\", "|", "/"}
i := 0
for {
select {
case <-done:
fmt.Printf("\rDone scanning! \n")
return
default:
fmt.Printf("\rScanning... %s", animationChars[i%len(animationChars)])
i++
time.Sleep(100 * time.Millisecond)
}
}
}
func main() {
UserIIP, err := GetInternalIP() // Get internal IP address
if err != nil {
fmt.Println("Error: ", err)
return
}
fmt.Println("My Internal IP: ", UserIIP)
UserEIP, err := GetExternalIP() // Get external IP address
if err != nil {
fmt.Println("Error: ", err)
return
}
fmt.Println("My External IP: ", UserEIP)
liveHosts := scanIPRange("10.0.0.1", "10.0.0.255")
var scannedHosts []Host
fmt.Println("Live hosts: ")
var wg sync.WaitGroup
var mutex sync.Mutex
for _, hostIP := range liveHosts {
wg.Add(1)
go func(ip string) {
defer wg.Done()
host := &Host{
IP: ip,
OpenPorts: scanPortsNmap(ip),
}
checkVulnerabilities(host)
mutex.Lock()
scannedHosts = append(scannedHosts, *host)
mutex.Unlock()
}(hostIP)
}
// Start loading animation in a separate goroutine
done := make(chan bool)
go loadingAnimation(done)
// Wait for all scanning goroutines to finish
wg.Wait()
done <- true // Stop the loading animation
generateReport(scannedHosts)
}