-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhash_identifier.go
47 lines (40 loc) · 891 Bytes
/
hash_identifier.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
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
// hash identifier
func hashIdentifier(hash string, extended bool) error {
url := "https://hashes.com/en/api/identifier?hash=" + hash
if extended {
url += "&extended=true"
}
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
var result map[string]interface{}
if err := json.Unmarshal(body, &result); err != nil {
return err
}
if success, ok := result["success"].(bool); ok && success {
if algorithms, ok := result["algorithms"].([]interface{}); ok && len(algorithms) > 0 {
fmt.Println("Possible Algorithms:")
for _, algo := range algorithms {
fmt.Printf(" %s\n", algo)
}
} else {
fmt.Println("No algorithms found.")
}
} else {
fmt.Println("No results found.")
}
return nil
}