修复IP位置显示
This commit is contained in:
@@ -266,8 +266,16 @@ func (s *Server) handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
|
||||
// 获取来源IP
|
||||
sourceIP := w.RemoteAddr().String()
|
||||
// 提取IP地址部分,去掉端口
|
||||
if idx := strings.LastIndex(sourceIP, ":"); idx >= 0 {
|
||||
sourceIP = sourceIP[:idx]
|
||||
if strings.HasPrefix(sourceIP, "[") {
|
||||
// IPv6地址格式: [::1]:53
|
||||
if idx := strings.Index(sourceIP, "]"); idx >= 0 {
|
||||
sourceIP = sourceIP[1:idx] // 去掉方括号
|
||||
}
|
||||
} else {
|
||||
// IPv4地址格式: 127.0.0.1:53
|
||||
if idx := strings.LastIndex(sourceIP, ":"); idx >= 0 {
|
||||
sourceIP = sourceIP[:idx]
|
||||
}
|
||||
}
|
||||
|
||||
// 更新来源IP统计
|
||||
|
||||
Reference in New Issue
Block a user