├── go.mod ├── README.md └── main.go /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/barisbaydur/waybackurls 2 | 3 | go 1.19 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # waybackurls 2 | 3 | Bring all the URLs that the Wayback machine knows for one or more domain names. 4 | 5 | Installation 6 | 7 | ``` 8 | ▶ go install github.com/barisbaydur/waybackurls@latest 9 | ``` 10 | 11 | Usage Example 12 | 13 | ``` 14 | ▶ waybackurls -hostFile -outFile 15 | ▶ waybackurls -host -outFile 16 | ▶ waybackurls -host 17 | ``` 18 | Use -hostFile to specify a file with a list of domains to check.
19 | Use -outFile to save the results to a file by domain name. If not used, the results will be printed to the terminal. 20 | 21 | Help 22 | 23 | ``` 24 | -host string 25 | This flag will specify a single domain to check. 26 | -hostFile string 27 | This flag will specify a file with a list of domains to check. 28 | -outFile 29 | This flag will save the results to a file by domain name. If not used, the results will be printed to the terminal. 30 | ``` 31 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "fmt" 7 | "io/ioutil" 8 | "log" 9 | "net/http" 10 | "os" 11 | ) 12 | 13 | var Usage = func() { 14 | fmt.Println(` 15 | Usage: 16 | Example: waybackurls -hostFile -outFile 17 | Example: waybackurls -host -outFile 18 | Example: waybackurls -host 19 | 20 | Use -hostFile to specify a file with a list of domains to check. 21 | Use -outFile to save the results to a file by domain name. If not used, the results will be printed to the terminal. 22 | `) 23 | fmt.Println("Flags:") 24 | flag.PrintDefaults() 25 | } 26 | 27 | func main() { 28 | outFile := flag.Bool("outFile", false, "This flag will save the results to a file by domain name. If not used, the results will be printed to the terminal.") 29 | hostFile := flag.String("hostFile", "", "This flag will specify a file with a list of domains to check.") 30 | host := flag.String("host", "", "This flag will specify a single domain to check.") 31 | flag.Parse() 32 | 33 | if *hostFile == "" && *host == "" { 34 | Usage() 35 | os.Exit(0) 36 | } 37 | 38 | if *host != "" { 39 | url := "https://web.archive.org/cdx/search/cdx?url=" + *host + "/*&output=text&fl=original&collapse=urlkey" 40 | resp, err := http.Get(url) 41 | if err != nil { 42 | log.Fatalln(err) 43 | } 44 | body, err := ioutil.ReadAll(resp.Body) 45 | if err != nil { 46 | log.Fatalln(err) 47 | } 48 | if string(body) != "" { 49 | if *outFile { 50 | os.WriteFile(*host+".txt", body, 0644) 51 | log.Printf("Done: " + *host) 52 | } else { 53 | fmt.Println(string(body)) 54 | } 55 | } else { 56 | log.Printf("No results for: " + *host) 57 | } 58 | } else { 59 | if _, err := os.Stat(*hostFile); os.IsNotExist(err) { 60 | log.Fatalln("File does not exist") 61 | } else { 62 | readFile, err := os.Open(*hostFile) 63 | if err != nil { 64 | log.Fatalln(err) 65 | } 66 | defer readFile.Close() 67 | 68 | fileScanner := bufio.NewScanner(readFile) 69 | fileScanner.Split(bufio.ScanLines) 70 | 71 | for fileScanner.Scan() { 72 | url := "https://web.archive.org/cdx/search/cdx?url=" + fileScanner.Text() + "/*&output=text&fl=original&collapse=urlkey" 73 | resp, err := http.Get(url) 74 | if err != nil { 75 | log.Fatalln(err) 76 | } 77 | body, err := ioutil.ReadAll(resp.Body) 78 | if err != nil { 79 | log.Fatalln(err) 80 | } 81 | defer resp.Body.Close() 82 | 83 | if string(body) != "" { 84 | if *outFile { 85 | os.WriteFile(fileScanner.Text()+".txt", body, 0644) 86 | log.Printf("Done: " + fileScanner.Text()) 87 | } else { 88 | fmt.Println(string(body)) 89 | } 90 | } else { 91 | log.Printf("No results for: " + fileScanner.Text()) 92 | } 93 | } 94 | } 95 | } 96 | } 97 | --------------------------------------------------------------------------------