From 970cff3b7251dcadefc79c27da3342c2264a7574 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Mon, 13 May 2024 20:42:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/cmd.go | 4 ++-- ipgeo/ipgeo_test.go | 8 ++++---- ipgeo/ipinfoLocal.go | 8 ++++---- trace/icmp_ipv4.go | 14 +++++++------- trace/icmp_ipv6.go | 6 +++--- trace/internal/icmp_darwin.go | 2 +- tracelog/log.go | 30 +++++++++++++++--------------- util/dot.go | 4 ++-- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 31b8f6a..41aff3d 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -148,7 +148,7 @@ func Excute() { } // DOMAIN处理结束 - capabilities_check() + capabilitiesCheck() // return var ip net.IP @@ -357,7 +357,7 @@ func Excute() { } } -func capabilities_check() { +func capabilitiesCheck() { // Windows 判断放在前面,防止遇到一些奇奇怪怪的问题 if runtime.GOOS == "windows" { diff --git a/ipgeo/ipgeo_test.go b/ipgeo/ipgeo_test.go index 120c2fa..c9b74af 100644 --- a/ipgeo/ipgeo_test.go +++ b/ipgeo/ipgeo_test.go @@ -16,13 +16,13 @@ import ( // ) func TestXxx(t *testing.T) { - const ID_FIXED_HEADER = "10" + const IdFixedHeader = "10" var processID = fmt.Sprintf("%07b", os.Getpid()&0x7f) //取进程ID的前7位 var ttl = fmt.Sprintf("%06b", 95) //取TTL的后6位 fmt.Println(os.Getpid()&0x7f, 95) var parity int - id := ID_FIXED_HEADER + processID + ttl + id := IdFixedHeader + processID + ttl for _, c := range id { if c == '1' { parity++ @@ -33,8 +33,8 @@ func TestXxx(t *testing.T) { } else { id += "0" } - process_id, ttl_r, _ := reverseID(id) - log.Println(process_id, ttl_r) + processId, ttlR, _ := reverseID(id) + log.Println(processId, ttlR) } func TestFilter(t *testing.T) { diff --git a/ipgeo/ipinfoLocal.go b/ipgeo/ipinfoLocal.go index b897017..cb2ed1f 100644 --- a/ipgeo/ipinfoLocal.go +++ b/ipgeo/ipinfoLocal.go @@ -33,19 +33,19 @@ func IPInfoLocal(ip string, _ time.Duration, _ string, _ bool) (*IPGeoData, erro return &IPGeoData{}, errors.New("no results") } recordMap := record.(map[string]interface{}) - country_name := recordMap["country_name"].(string) + countryName := recordMap["country_name"].(string) prov := "" if recordMap["country"].(string) == "HK" { - country_name = "China" + countryName = "China" prov = "Hong Kong" } if recordMap["country"].(string) == "TW" { - country_name = "China" + countryName = "China" prov = "Taiwan" } return &IPGeoData{ Asnumber: strings.TrimPrefix(recordMap["asn"].(string), "AS"), - Country: country_name, + Country: countryName, City: "", Prov: prov, Owner: recordMap["as_name"].(string), diff --git a/trace/icmp_ipv4.go b/trace/icmp_ipv4.go index 6adb64f..f253c8e 100644 --- a/trace/icmp_ipv4.go +++ b/trace/icmp_ipv4.go @@ -151,9 +151,9 @@ func (t *ICMPTracer) listenICMP() { continue } ttl := int64(binary.BigEndian.Uint16(msg.Msg[34:36])) - packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[32:34])), 2) - if process_id, _, err := reverseID(packet_id); err == nil { - if process_id == int64(os.Getpid()&0x7f) { + packetId := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[32:34])), 2) + if processId, _, err := reverseID(packetId); err == nil { + if processId == int64(os.Getpid()&0x7f) { dstip := net.IP(msg.Msg[24:28]) if dstip.Equal(t.DestIP) || dstip.Equal(net.IPv4zero) { // 匹配再继续解析包,否则直接丢弃 @@ -202,13 +202,13 @@ func (t *ICMPTracer) handleICMPMessage(msg ReceivedMessage, icmpType int8, data } } -func gernerateID(ttl_int int) int { - const ID_FIXED_HEADER = "10" +func gernerateID(ttlInt int) int { + const IdFixedHeader = "10" var processID = fmt.Sprintf("%07b", os.Getpid()&0x7f) //取进程ID的前7位 - var ttl = fmt.Sprintf("%06b", ttl_int) //取TTL的后6位 + var ttl = fmt.Sprintf("%06b", ttlInt) //取TTL的后6位 var parity int - id := ID_FIXED_HEADER + processID + ttl + id := IdFixedHeader + processID + ttl for _, c := range id { if c == '1' { parity++ diff --git a/trace/icmp_ipv6.go b/trace/icmp_ipv6.go index dfd9f83..4fb2106 100644 --- a/trace/icmp_ipv6.go +++ b/trace/icmp_ipv6.go @@ -172,9 +172,9 @@ func (t *ICMPTracerv6) listenICMP() { } ttl := int64(binary.BigEndian.Uint16(msg.Msg[54:56])) - packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[52:54])), 2) - if process_id, _, err := reverseID(packet_id); err == nil { - if process_id == int64(os.Getpid()&0x7f) { + packetId := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[52:54])), 2) + if processId, _, err := reverseID(packetId); err == nil { + if processId == int64(os.Getpid()&0x7f) { dstip := net.IP(msg.Msg[32:48]) // 无效包本地环回包 if dstip.String() == "::" { diff --git a/trace/internal/icmp_darwin.go b/trace/internal/icmp_darwin.go index 384038c..2605f3c 100644 --- a/trace/internal/icmp_darwin.go +++ b/trace/internal/icmp_darwin.go @@ -39,7 +39,7 @@ func ListenICMP(network string, laddr string) (net.PacketConn, error) { proto = syscall.IPPROTO_ICMPV6 } - var ifIndex int = -1 + var ifIndex = -1 if laddr != "" { la := net.ParseIP(laddr) if ifaces, err := net.Interfaces(); err == nil { diff --git a/tracelog/log.go b/tracelog/log.go index e2f2569..8b76074 100644 --- a/tracelog/log.go +++ b/tracelog/log.go @@ -27,8 +27,8 @@ func RealtimePrinter(res *trace.Result, ttl int) { multiWriter := io.MultiWriter(os.Stdout, f) log.SetOutput(multiWriter) log.SetFlags(0) - var res_str string - res_str += fmt.Sprintf("%-2d ", ttl+1) + var resStr string + resStr += fmt.Sprintf("%-2d ", ttl+1) // 去重 var latestIP string @@ -56,28 +56,28 @@ func RealtimePrinter(res *trace.Result, ttl int) { } if latestIP == "" { - res_str += fmt.Sprintf("%s\n", "*") - log.Print(res_str) + resStr += fmt.Sprintf("%s\n", "*") + log.Print(resStr) return } var blockDisplay = false for ip, v := range tmpMap { if blockDisplay { - res_str += fmt.Sprintf("%4s", "") + resStr += fmt.Sprintf("%4s", "") } if net.ParseIP(ip).To4() == nil { - res_str += fmt.Sprintf("%-25s ", ip) + resStr += fmt.Sprintf("%-25s ", ip) } else { - res_str += fmt.Sprintf("%-15s ", ip) + resStr += fmt.Sprintf("%-15s ", ip) } i, _ := strconv.Atoi(v[0]) if res.Hops[ttl][i].Geo.Asnumber != "" { - res_str += fmt.Sprintf("AS%-7s", res.Hops[ttl][i].Geo.Asnumber) + resStr += fmt.Sprintf("AS%-7s", res.Hops[ttl][i].Geo.Asnumber) } else { - res_str += fmt.Sprintf(" %-8s", "*") + resStr += fmt.Sprintf(" %-8s", "*") } if net.ParseIP(ip).To4() != nil { @@ -89,7 +89,7 @@ func RealtimePrinter(res *trace.Result, ttl int) { if whoisFormat[0] != "" { whoisFormat[0] = "[" + whoisFormat[0] + "]" } - res_str += fmt.Sprintf("%-16s", whoisFormat[0]) + resStr += fmt.Sprintf("%-16s", whoisFormat[0]) } if res.Hops[ttl][i].Geo.Country == "" { @@ -98,19 +98,19 @@ func RealtimePrinter(res *trace.Result, ttl int) { if net.ParseIP(ip).To4() != nil { - res_str += fmt.Sprintf(" %s %s %s %s %-6s\n %-39s ", res.Hops[ttl][i].Geo.Country, res.Hops[ttl][i].Geo.Prov, res.Hops[ttl][i].Geo.City, res.Hops[ttl][i].Geo.District, res.Hops[ttl][i].Geo.Owner, res.Hops[ttl][i].Hostname) + resStr += fmt.Sprintf(" %s %s %s %s %-6s\n %-39s ", res.Hops[ttl][i].Geo.Country, res.Hops[ttl][i].Geo.Prov, res.Hops[ttl][i].Geo.City, res.Hops[ttl][i].Geo.District, res.Hops[ttl][i].Geo.Owner, res.Hops[ttl][i].Hostname) } else { - res_str += fmt.Sprintf(" %s %s %s %s %-6s\n %-35s ", res.Hops[ttl][i].Geo.Country, res.Hops[ttl][i].Geo.Prov, res.Hops[ttl][i].Geo.City, res.Hops[ttl][i].Geo.District, res.Hops[ttl][i].Geo.Owner, res.Hops[ttl][i].Hostname) + resStr += fmt.Sprintf(" %s %s %s %s %-6s\n %-35s ", res.Hops[ttl][i].Geo.Country, res.Hops[ttl][i].Geo.Prov, res.Hops[ttl][i].Geo.City, res.Hops[ttl][i].Geo.District, res.Hops[ttl][i].Geo.Owner, res.Hops[ttl][i].Hostname) } for j := 1; j < len(v); j++ { if len(v) == 2 || j == 1 { - res_str += v[j] + resStr += v[j] } else { - res_str += fmt.Sprintf("/ %s", v[j]) + resStr += fmt.Sprintf("/ %s", v[j]) } } - log.Print(res_str) + log.Print(resStr) blockDisplay = true } } diff --git a/util/dot.go b/util/dot.go index 321ad65..fdc0239 100644 --- a/util/dot.go +++ b/util/dot.go @@ -14,7 +14,7 @@ func newDoTResolver(serverName string, addrs string) *net.Resolver { Timeout: 1000 * time.Millisecond, } - tls_config := &tls.Config{ + tlsConfig := &tls.Config{ // 设置 TLS Server Name 以确保证书能和域名对应 ServerName: serverName, } @@ -26,7 +26,7 @@ func newDoTResolver(serverName string, addrs string) *net.Resolver { if err != nil { return nil, err } - return tls.Client(conn, tls_config), nil + return tls.Client(conn, tlsConfig), nil }, } }