优化代码

This commit is contained in:
GoEdgeLab
2024-04-06 10:07:47 +08:00
parent 5893fd7b3a
commit c3b945b29a

View File

@@ -4,7 +4,7 @@ package iputils
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "encoding/hex"
"math" "math"
"math/big" "math/big"
"net" "net"
@@ -111,10 +111,10 @@ func ToHex(ip string) string {
} }
if rawIP.To4() != nil { if rawIP.To4() != nil {
return fmt.Sprintf("%x", rawIP.To4()) return hex.EncodeToString(rawIP.To4())
} }
return fmt.Sprintf("%x", rawIP.To16()) return hex.EncodeToString(rawIP.To16())
} }
func ToLittleLong(ip string) string { func ToLittleLong(ip string) string {