diff --git a/main.go b/main.go index 427b5e2..a93cd46 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ * @Author: ph4nt0mer * @Date: 2022-08-31 17:03:03 * @LastEditors: rootphantomer - * @LastEditTime: 2022-09-06 15:56:53 + * @LastEditTime: 2022-09-06 16:39:06 * @FilePath: /quake_go/main.go * @Description: * @@ -34,7 +34,9 @@ Usage of ./quake: info person infomation query - query string + query string value + -t + field string value(example:./quake query port:8088 -t ip,port) -size string size String value (default "10") -start string @@ -55,7 +57,7 @@ Usage of ./quake: fmt.Println("!!!!please ./quake init token!!!!") return } - start, size, _ := flaginit() + start, size, field := flaginit() switch strings.ToLower(os.Args[1]) { case "info": apis.InfoGet(token.Token) @@ -64,7 +66,7 @@ Usage of ./quake: fmt.Println("!!!!query is empty !!!!") return } - apis.SearchServicePost(os.Args[2], start, size, token.Token) + apis.SearchServicePost(os.Args[2], start, size, token.Token, field) case "host": fmt.Println("主机数据接口待完成。。。") case "favicon": diff --git a/src/apis/api.go b/src/apis/api.go index adb4d29..8c64adb 100644 --- a/src/apis/api.go +++ b/src/apis/api.go @@ -2,7 +2,7 @@ * @Author: ph4nt0mer * @Date: 2022-09-01 15:36:10 * @LastEditors: rootphantomer - * @LastEditTime: 2022-09-06 15:41:39 + * @LastEditTime: 2022-09-06 16:41:22 * @FilePath: /quake_go/src/apis/api.go * @Description: * @@ -14,6 +14,8 @@ import ( "fmt" "quake/src/setting" "quake/src/tools" + "quake/src/utils" + "strconv" ) func FilterableServiceGET(token string) { @@ -22,7 +24,7 @@ func FilterableServiceGET(token string) { uri := "/filterable/field/quake_service" tools.ApisGet(setting.URL+uri, token) } -func SearchServicePost(query string, start string, size string, token string) { +func SearchServicePost(query string, start string, size string, token string, field string) { // 服务数据实时查询接口 // curl -X POST "https://quake.360.cn/api/v3/search/quake_service" -H "X-QuakeToken: d17140ae-xxxx-xxx-xxxx-c0818b2bbxxx" -H "Content-Type: application/json" -d '{ // "query": "service: http", @@ -40,7 +42,22 @@ func SearchServicePost(query string, start string, size string, token string) { payload := "{\"query\":\"" + query + "\",\"start\":\"" + start + "\",\"size\":\"" + size + "\"}" - tools.ApisPost(setting.URL+uri, payload, start, size, token) + + body := tools.ApisPost(setting.URL+uri, payload, start, size, token) + resut := utils.SeriveLoadJson(body) + data := resut.Data + // if field != "" { + // fields := strings.Split(field, ",") + // for _, fields_value := range fields { + // for _, value := range data { + // fmt.Println(value.fields_value) + // } + // } + // } + for _, value := range data { + fmt.Println(value.IP + ":" + strconv.Itoa(value.Port)) + } + } func ScrollServicePost(query string, start string, size string, token string) { // 服务数据深度查询接口 diff --git a/src/tools/commond.go b/src/tools/commond.go index dc04f58..7c98e5e 100644 --- a/src/tools/commond.go +++ b/src/tools/commond.go @@ -2,7 +2,7 @@ * @Author: ph4nt0mer * @Date: 2022-09-01 10:49:31 * @LastEditors: rootphantomer - * @LastEditTime: 2022-09-06 15:59:42 + * @LastEditTime: 2022-09-06 16:22:21 * @FilePath: /quake_go/src/tools/commond.go * @Description: * @@ -18,13 +18,13 @@ import ( "strings" ) -func ApisPost(url string, payload string, start string, size string, token string) { +func ApisPost(url string, payload string, start string, size string, token string) string { var jsonStr = []byte(payload) client := &http.Client{} req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) if err != nil { fmt.Println(err) - return + return err.Error() } req.Header.Add("X-QuakeToken", token) req.Header.Add("Content-Type", "application/json") @@ -32,27 +32,28 @@ func ApisPost(url string, payload string, start string, size string, token strin res, err := client.Do(req) if err != nil { fmt.Println(err) - return + return err.Error() } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) - return + return err.Error() } fmt.Println("result:") - fmt.Println(string(body)) + // fmt.Println(string(body)) if strings.Contains(string(body), "quake/login") { fmt.Println("token expired,please init new token") } + return string(body) } -func ApisGet(url string, token string) { +func ApisGet(url string, token string) string { client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println(err) - return + return err.Error() } req.Header.Add("X-QuakeToken", token) req.Header.Add("Content-Type", "application/json") @@ -60,18 +61,19 @@ func ApisGet(url string, token string) { res, err := client.Do(req) if err != nil { fmt.Println(err) - return + return err.Error() } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) - return + return err.Error() } fmt.Println("result:") - fmt.Println(string(body)) + // fmt.Println(string(body)) if strings.Contains(string(body), "quake/login") { fmt.Println("token expired,please init new token") } + return string(body) } diff --git a/src/utils/LoadJson.go b/src/utils/LoadJson.go new file mode 100644 index 0000000..e30d411 --- /dev/null +++ b/src/utils/LoadJson.go @@ -0,0 +1,110 @@ +/* + * @Author: rootphantomer zhoufei1@360.cn + * @Date: 2022-09-06 16:04:43 + * @LastEditors: rootphantomer + * @LastEditTime: 2022-09-06 16:42:24 + * @FilePath: /quake_go/src/utils/LoadJson.go + * @Description: + * + * Copyright (c) 2022 by rootphantomer, All Rights Reserved. + */ +package utils + +import ( + "encoding/json" + "fmt" +) + +type ServiceJson struct { + Code int64 `json:"code"` + Data []struct { + Asn int64 `json:"asn"` + Cdn struct { + Domain string `json:"domain"` + IsCdn bool `json:"is_cdn"` + } `json:"cdn"` + Components []struct { + ID string `json:"id"` + ProductCatalog []string `json:"product_catalog"` + ProductLevel string `json:"product_level"` + ProductNameCn string `json:"product_name_cn"` + ProductNameEn string `json:"product_name_en"` + ProductType []string `json:"product_type"` + ProductVendor string `json:"product_vendor"` + Version string `json:"version"` + } `json:"components"` + Hostname string `json:"hostname"` + ID string `json:"id"` + Images []interface{} `json:"images"` + IP string `json:"ip"` + IsIpv6 bool `json:"is_ipv6"` + Location struct { + CityCn string `json:"city_cn"` + CityEn string `json:"city_en"` + CountryCn string `json:"country_cn"` + CountryCode string `json:"country_code"` + CountryEn string `json:"country_en"` + DistrictCn string `json:"district_cn"` + DistrictEn string `json:"district_en"` + Isp string `json:"isp"` + ProvinceCn string `json:"province_cn"` + ProvinceEn string `json:"province_en"` + Radius float64 `json:"radius"` + SceneCn string `json:"scene_cn"` + SceneEn string `json:"scene_en"` + } `json:"location"` + Org string `json:"org"` + OsName string `json:"os_name"` + OsVersion string `json:"os_version"` + Port int `json:"port"` + Service struct { + Banner string `json:"banner"` + Cert string `json:"cert"` + HTTP struct { + Body string `json:"body"` + Favicon struct { + Data string `json:"data"` + Hash string `json:"hash"` + Location string `json:"location"` + } `json:"favicon"` + Host string `json:"host"` + HTMLHash string `json:"html_hash"` + MetaKeywords string `json:"meta_keywords"` + Path string `json:"path"` + ResponseHeaders string `json:"response_headers"` + Server string `json:"server"` + StatusCode int64 `json:"status_code"` + Title string `json:"title"` + XPoweredBy string `json:"x_powered_by"` + } `json:"http"` + Name string `json:"name"` + Product string `json:"product"` + Response string `json:"response"` + Version string `json:"version"` + } `json:"service"` + SysTag []string `json:"sys_tag"` + Time string `json:"time"` + Transport string `json:"transport"` + } `json:"data"` + Message string `json:"message"` + Meta struct { + Pagination struct { + Count int64 `json:"count"` + PageIndex int64 `json:"page_index"` + PageSize int64 `json:"page_size"` + Total int64 `json:"total"` + } `json:"pagination"` + } `json:"meta"` +} + +func SeriveLoadJson(body string) (result ServiceJson) { + var serivejson ServiceJson + if err := json.Unmarshal([]byte(body), &serivejson); err == nil { + // fmt.Println(serivejson.Data) + // data := serivejson.Data + result = serivejson + } else { + fmt.Println(err) + } + return +}