Skip to content

Commit

Permalink
chore: add traceMap (new)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlleo committed Dec 17, 2022
1 parent 336151d commit 91cd4fb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ipgeo/ipgeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 6 additions & 0 deletions ipgeo/leo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ipgeo
import (
"encoding/json"
"errors"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -56,13 +57,18 @@ 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(),
Prov: res.Get("prov").String(),
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(),
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"log"
Expand All @@ -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"
)
Expand All @@ -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")
Expand Down Expand Up @@ -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 changes: 20 additions & 0 deletions tracemap/tracemap.go
Original file line number Diff line number Diff line change
@@ -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)),
)
}

0 comments on commit 91cd4fb

Please sign in to comment.