-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (32 loc) · 789 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
package main
import (
"encoding/json"
"io"
"net"
"net/http"
"net/url"
"pentest_tools/modules"
)
func main() {
http.HandleFunc("/api/portscan", portScannerHandler)
err := http.ListenAndServe(":8000", nil)
if err != nil {
panic(err)
}
}
func portScannerHandler(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
address := query.Get("address")
ports := query.Get("ports")
_, urlErr := url.Parse(address)
if address == "" || (net.ParseIP(address) == nil && urlErr != nil) {
io.WriteString(w, "please enter a valid IP or url")
return
}
var options modules.ScanOptions
options.Address = address
options.Ports = ports
openPorts := modules.ScanPorts(options)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(openPorts)
}