Skip to content

Commit

Permalink
refactor(port): optimize port scanning logic and remove debug logs
Browse files Browse the repository at this point in the history
- Remove all debug logging statements for cleaner output
- Optimize TCP port scanning to return true on successful connection
- Keep HTTP client configuration for better compatibility
- Restore timeout settings to 2 seconds for faster scanning
  • Loading branch information
Your Name committed Dec 15, 2024
1 parent 7d09d0a commit 472ed62
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions pkg/stage/port.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stage

import (
"crypto/tls"
"fmt"
"net"
"net/http"
Expand All @@ -27,13 +28,39 @@ func ScanTCPPort(ip string, port int) bool {

func ScanHTTPPort(ip string, port int) bool {
target := fmt.Sprintf("http://%s:%d", ip, port)

transport := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS10,
MaxVersion: tls.VersionTLS13,
},
DisableKeepAlives: true,
DialContext: (&net.Dialer{
Timeout: 10 * time.Second,
KeepAlive: 10 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 10 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
ExpectContinueTimeout: 10 * time.Second,
}

client := &http.Client{
Timeout: 2 * time.Second,
Transport: transport,
Timeout: 10 * time.Second,
}

resp, err := client.Head(target)
if err != nil {
return false
if port == 80 || port == 443 {
httpsTarget := fmt.Sprintf("https://%s:%d", ip, port)
resp, err = client.Head(httpsTarget)
if err != nil {
return false
}
} else {
return false
}
}
defer resp.Body.Close()
return true
Expand All @@ -46,6 +73,5 @@ func ScanUDPPort(ip string, port int) bool {
return false
}
defer conn.Close()

return true
}

0 comments on commit 472ed62

Please sign in to comment.