This commit is contained in:
2025-11-21 18:30:09 +08:00
parent e6a9a7a1f4
commit 27806421f7
5 changed files with 861 additions and 120 deletions

View File

@@ -8,11 +8,31 @@ import (
)
func handleTrace(c *gin.Context, url string, params map[string]interface{}) {
// 获取seq参数
seq := ""
if seqVal, ok := params["seq"].(string); ok {
seq = seqVal
}
// 解析URL提取hostname
hostname := url
if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
parts := strings.Split(url, "//")
if len(parts) > 1 {
hostParts := strings.Split(parts[1], "/")
hostname = hostParts[0]
if idx := strings.Index(hostname, ":"); idx != -1 {
hostname = hostname[:idx]
}
}
}
// 执行traceroute命令
cmd := exec.Command("traceroute", url)
cmd := exec.Command("traceroute", "-m", "30", "-n", hostname)
output, err := cmd.CombinedOutput()
if err != nil {
c.JSON(200, gin.H{
"seq": seq,
"type": "ceTrace",
"url": url,
"error": err.Error(),
@@ -31,6 +51,7 @@ func handleTrace(c *gin.Context, url string, params map[string]interface{}) {
}
c.JSON(200, gin.H{
"seq": seq,
"type": "ceTrace",
"url": url,
"trace_result": traceResult,