chore: add traceMap (new)

This commit is contained in:
sjlleo
2022-12-17 04:14:39 -05:00
parent 336151dc1b
commit 91cd4fb8f4
4 changed files with 37 additions and 0 deletions

View File

@@ -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"`

View File

@@ -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(),

View File

@@ -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))
}
}

20
tracemap/tracemap.go Normal file
View File

@@ -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)),
)
}