Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
新增默认输入的body为ip:port
Browse files Browse the repository at this point in the history
  • Loading branch information
rootphantomer committed Sep 6, 2022
1 parent d5866c9 commit 8131d44
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 18 deletions.
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -34,7 +34,9 @@ Usage of ./quake:
info
person infomation
query <string>
query string
query string value
-t <string,string>
field string value(example:./quake query port:8088 -t ip,port)
-size string
size String value (default "10")
-start string
Expand All @@ -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)
Expand All @@ -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":
Expand Down
23 changes: 20 additions & 3 deletions src/apis/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand All @@ -14,6 +14,8 @@ import (
"fmt"
"quake/src/setting"
"quake/src/tools"
"quake/src/utils"
"strconv"
)

func FilterableServiceGET(token string) {
Expand All @@ -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",
Expand All @@ -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) {
// 服务数据深度查询接口
Expand Down
24 changes: 13 additions & 11 deletions src/tools/commond.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand All @@ -18,60 +18,62 @@ 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")

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")

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)
}
110 changes: 110 additions & 0 deletions src/utils/LoadJson.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* @Author: rootphantomer [email protected]
* @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
}

0 comments on commit 8131d44

Please sign in to comment.