-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.go
More file actions
93 lines (76 loc) · 2.02 KB
/
main.go
File metadata and controls
93 lines (76 loc) · 2.02 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
func getcve(url string) {
// Get request
req, err := http.Get(url)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0")
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Fatalln(err)
}
// JSON unmarshalling
var result map[string]interface{}
json.Unmarshal([]byte(body), &result)
data := result["data"].([]interface{})
for _, value := range data {
fmt.Println(value.(map[string]interface{})["cve"])
}
}
func getcveinfo(url string) {
// Get request
req, err := http.Get(url)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0")
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Fatalln(err)
}
// JSON unmarshalling
var result map[string]interface{}
json.Unmarshal([]byte(body), &result)
data := result["data"].([]interface{})
for _, value := range data {
cve := value.(map[string]interface{})["cve"]
cveinfo := value.(map[string]interface{})["description"]
cveseverity := value.(map[string]interface{})["severity"]
fmt.Println(cve, "\n", "Description: ", cveinfo, "\n", "Severity :", cveseverity)
fmt.Println("-----------------------------------")
}
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: gofetch day|week [-info]")
return
} else if os.Args[1] == "day" {
if len(os.Args) == 3 && os.Args[2] == "-info" {
url := "https://cvetrends.com/api/cves/24hrs"
getcveinfo(url)
} else {
url := "https://cvetrends.com/api/cves/24hrs"
getcve(url)
}
} else if os.Args[1] == "week" {
if len(os.Args) == 3 && os.Args[2] == "-info" {
url := "https://cvetrends.com/api/cves/order-by-tweets-7days"
getcveinfo(url)
} else {
url := "https://cvetrends.com/api/cves/order-by-tweets-7days"
getcve(url)
}
} else {
fmt.Println("Usage: gofetch day|week [-info]")
return
}
}