diff --git a/ipgeo/ipgeo.go b/ipgeo/ipgeo.go index 55912e5..4ee778e 100644 --- a/ipgeo/ipgeo.go +++ b/ipgeo/ipgeo.go @@ -15,6 +15,8 @@ type IPGeoData struct { Isp string `json:"isp"` Domain string `json:"domain"` Whois string `json:"whois"` + Lat float64 `json:"lat"` + Lng float64 `json:"lng"` Prefix string `json:"prefix"` Router map[string][]string `json:"router"` Source string `json:"source"` diff --git a/ipgeo/leo.go b/ipgeo/leo.go index c142557..98d5c63 100644 --- a/ipgeo/leo.go +++ b/ipgeo/leo.go @@ -3,6 +3,7 @@ package ipgeo import ( "encoding/json" "errors" + "strconv" "sync" "time" @@ -56,6 +57,9 @@ func receiveParse() { m := make(map[string][]string) json.Unmarshal([]byte(res.Get("router").String()), &m) + lat, _ := strconv.ParseFloat(res.Get("lat").String(), 32) + lng, _ := strconv.ParseFloat(res.Get("lng").String(), 32) + IPPools.pool[gjson.Parse(data).Get("ip").String()] <- IPGeoData{ Asnumber: res.Get("asnumber").String(), Country: res.Get("country").String(), @@ -63,6 +67,8 @@ func receiveParse() { City: res.Get("city").String(), District: res.Get("district").String(), Owner: domain, + Lat: lat, + Lng: lng, Isp: res.Get("isp").String(), Whois: res.Get("whois").String(), Prefix: res.Get("prefix").String(), diff --git a/main.go b/main.go index f0c4f12..1f9f4a5 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "flag" "fmt" "log" @@ -18,6 +19,7 @@ import ( "github.com/xgadget-lab/nexttrace/reporter" "github.com/xgadget-lab/nexttrace/trace" "github.com/xgadget-lab/nexttrace/tracelog" + "github.com/xgadget-lab/nexttrace/tracemap" "github.com/xgadget-lab/nexttrace/util" "github.com/xgadget-lab/nexttrace/wshandle" ) @@ -37,6 +39,7 @@ var output = fSet.Bool("o", false, "Ouput trace result to file (RealTimePrinter var tablePrint = fSet.Bool("table", false, "Output trace results as table") var classicPrint = fSet.Bool("classic", false, "Classic Output trace results like BestTrace") var beginHop = fSet.Int("b", 1, "Set The Begin TTL") +var maptrace = fSet.Bool("M", false, "Print Trace Map") var ver = fSet.Bool("V", false, "Print Version") var src_addr = fSet.String("S", "", "Use the following IP address as the source address in outgoing packets") var src_dev = fSet.String("D", "", "Use the following Network Devices as the source address in outgoing packets") @@ -235,4 +238,10 @@ func main() { r := reporter.New(res, ip.String()) r.Print() } + + if *maptrace { + r, _ := json.Marshal(res) + tracemap.GetMapUrl(string(r)) + } + } diff --git a/tracemap/tracemap.go b/tracemap/tracemap.go new file mode 100644 index 0000000..e00a195 --- /dev/null +++ b/tracemap/tracemap.go @@ -0,0 +1,20 @@ +package tracemap + +import ( + "fmt" + "io" + "net/http" + "strings" + + "github.com/fatih/color" +) + +func GetMapUrl(r string) { + url := "https://api.leo.moe/tracemap/api" + resp, _ := http.Post(url, "application/json", strings.NewReader(string(r))) + body, _ := io.ReadAll(resp.Body) + fmt.Fprintf(color.Output, "%s %s\n", + color.New(color.FgWhite, color.Bold).Sprintf("%s", "MapTrace URL:"), + color.New(color.FgBlue, color.Bold).Sprintf("%s", string(body)), + ) +}