From 9e6c362ec0d1ae65bc9535abd5a6cb7d5047b04b Mon Sep 17 00:00:00 2001 From: sML Date: Tue, 27 Dec 2022 10:08:03 +0100 Subject: [PATCH] first commit --- fbroken.go | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 fbroken.go diff --git a/fbroken.go b/fbroken.go new file mode 100755 index 0000000..5ac2af1 --- /dev/null +++ b/fbroken.go @@ -0,0 +1,108 @@ +/* +Description: Tool to check alive URLs. +Auth0r: sml@lacashita.com + +Use it only as educational purpose. +*/ + +package main + +import ( + "bufio" + "flag" + "fmt" + "net/http" + "os" + "sync" + "time" +) + +// Func to check if URL works. +func checkUrl(page string, client http.Client, wg *sync.WaitGroup) { + defer wg.Done() + request, err := http.NewRequest("GET", page, nil) + if err != nil { + fmt.Printf("Error requesting url.\n") + } + response, err := client.Do(request) + if err != nil { + // Shows the errors in requests. + fmt.Printf("Error in the URL: %v with the error %v\n", page, err) + } else { + if response.StatusCode == 200 { + // Uncomment the following line to check what pages are OK (Status 200). + // fmt.Printf("Page %v OK\n",page) + defer response.Body.Close() + } else { + // Shows URLs with errors (Status != 200). + fmt.Printf("Page %v with errors.\n",page) + } + } +} + +var wg sync.WaitGroup + +func lanomalie() { +fmt.Println(` + __ _ _ + / _| | | | + | |_| |__ _ __ ___ | | _____ _ __ + | _| '_ \| '__/ _ \| |/ / _ \ '_ \ + | | | |_) | | | (_) | < __/ | | | + |_| |_.__/|_| \___/|_|\_\___|_| |_| +===================================== +[-] Checking alive URLs... + + `) +} + +func main() { + var page string + fichero := flag.String("f", "", "File with urls") + web := flag.String("u", "", "Only one url") + flag.Parse() + client := http.Client{Timeout: 10 * time.Second} + // Check there are at least 2 args. + if len(os.Args) < 2 { + fmt.Println(` +Parameters: +-f File with URLs to check. +-u URL to check. + +Examples to check file with URLs: +fbroken -f urls.txt + +Example to check URL: +fbroken -u https://domain.xxx + `) + os.Exit(1) + } + + switch os.Args[1] { + case "-f": + lanomalie() + // Open file and check URLs + file, err := os.Open(*fichero) + if err != nil { + fmt.Print("Error opening the file") + } + defer file.Close() + scanner := bufio.NewScanner(file) + for scanner.Scan() { + page = scanner.Text() + go checkUrl(page, client, &wg) + wg.Add(1) + } + + case "-u": + lanomalie() + // Check directly the URL. + go checkUrl(*web, client, &wg) + wg.Add(1) + default: + fmt.Println("-f or -u expected") + os.Exit(1) + } + wg.Wait() + +}