first commit

This commit is contained in:
sML 2022-12-27 10:08:03 +01:00
commit 9e6c362ec0

108
fbroken.go Executable file
View File

@ -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()
}