Loading...
## 前言
前段时间看到一个监控Github开源CVE漏洞利用的爬虫,然后最近柚子啊看golang,所以用golang写了以下,准备后面用golang的gin框架写一个简单的网站,来实时监控
## 详细过程
接口:https://api.github.com/search/repositories?q=CVE-2020&sort=updated
这里其实就是利用的github的搜索,挺简单的,我们通过搜索CVE-year的关键字,将搜索接口返回的数据格式化以下,提取出主要的名称,描述,和仓库地址就可以了
## 代码
```
/**
2 * @Author: JsOnGmAX
3 * @Date: 2020/8/5 11:31
4 */
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
type Items struct {
Name string `json:"name"`
SvnUrl string `json:"svn_url"`
Description string `json:"description"`
}
type Result struct {
TotalCount int64 `json:"total_count"`
IncompleteResults bool `json:"incomplete_results"`
Items []Items `json:"items"`
}
func CheckErr(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
timeNow := time.Now().Year()
UrlIndex := fmt.Sprintf("https://api.github.com/search/repositories?q=CVE-%d&sort=updated",timeNow)
resp, err := http.Get(UrlIndex)
CheckErr(err)
result := Result{}
body, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal([]byte(body), &result)
fmt.Println(fmt.Sprintf("%+v",result))
resp.Body.Close()
}
```
## 效果
![image.png](https://jsong.cn/usr/uploads/2020/08/1557981559.png)
版权属于:JsOnGmAX
本文链接:https://jsong.cn/archives/614.html
博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议 如有侵权 请联系本人删除
最后修改:2020 年 08 月 06 日 09 : 42 AM
© 允许规范转载
赞赏
如果觉得我的文章对你有用,请随意赞赏
×Close
赞赏作者
扫一扫支付
支付宝支付
微信支付