Skip to content

Commit 6836cf1

Browse files
author
invoker
committed
check host up and down
1 parent 608e3e2 commit 6836cf1

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

main.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ func main() {
5858
println("please set url with --url or -h for help")
5959
return
6060
}
61+
62+
// Add site availability check
63+
if !checkSiteIsUp(*address) {
64+
fmt.Printf("🚨 Host %s is unreachable, aborting scan\n", *address)
65+
return
66+
}
67+
6168
//ex, err := os.Executable()
62-
//if err != nil {
69+
//if err != nil {go
6370
// panic(err)
6471
//}
6572
//exPath := filepath.Dir(ex)
@@ -121,11 +128,6 @@ func main() {
121128
}
122129
}
123130

124-
totalFiles := 0
125-
for _, files := range successlist {
126-
totalFiles += len(files)
127-
}
128-
129131
switch formatType {
130132
case "json":
131133
writeJSONOutput(successlist, outputDir)
@@ -308,3 +310,26 @@ func printResults(results map[string][]string) {
308310
fmt.Println()
309311
}
310312
}
313+
314+
// Add new function for site availability check
315+
func checkSiteIsUp(url string) bool {
316+
client := &http.Client{
317+
Timeout: 20 * time.Second,
318+
Transport: &http.Transport{
319+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
320+
},
321+
}
322+
323+
resp, err := client.Head(url)
324+
if err != nil {
325+
return false
326+
}
327+
defer resp.Body.Close()
328+
329+
// Consider any 2xx/3xx status as "up"
330+
if resp.StatusCode >= 200 && resp.StatusCode < 400 {
331+
fmt.Printf("✅ Host is reachable (%s)\n", resp.Status)
332+
return true
333+
}
334+
return false
335+
}

0 commit comments

Comments
 (0)