forked from lorenzoromani1983/wayback-keyword-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
55 lines (52 loc) · 1.42 KB
/
search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"os"
"strings"
"bufio"
)
func listdir(domain string) []string {
var fileList []string
dir, _ := os.Getwd()
file_path := dir+"/"+domain+"/"
fmt.Println("Searching in:",file_path,"\n")
files, _ := os.ReadDir(file_path)
for _, file := range files {
fileName := file.Name()
fileList = append(fileList, file_path+fileName)
}
return fileList
}
func printUrl(filename string) {
array := strings.Split(filename, "/")
webpath := strings.Replace(array[len(array)-1],"$",":",-1)
webpath_ := strings.Replace(webpath, "£", "/",-1)
webpath__ := strings.Replace(webpath_, "!!!", ":",-1)
webpath___ := strings.Replace(webpath__, "§§", "?", -1)
webpath_final := strings.Replace(webpath___, ".txt","",1)
fmt.Println(webpath_final)
}
func main() {
var domain string
fmt.Print("Specify the target domain (only lowercase): ")
fmt.Scanln(&domain)
fmt.Print("Type your keyword below (case insensitive): ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
input := strings.ToLower(scanner.Text())
fmt.Println("Searching for:",input)
for _, file_ := range listdir(domain) {
file, _ := os.Open(file_)
defer file.Close()
scanner = bufio.NewScanner(file)
for scanner.Scan() {
line := strings.ToLower(scanner.Text())
if strings.Contains(line, input) {
printUrl(file_)
break
}
}
}
fmt.Println("Search finished, press enter to close window")
fmt.Scanln()
}