我想使用 Go 获取客户端缓存 DNS IP看看我在下面尝试的代码import ( "fmt" "net")func main() { // Usually DNS Server using 53 port number // This case, TCP protocol is not considered port := ":53" protocol := "udp" var buf [2048]byte //Build the address udpAddr, err := net.ResolveUDPAddr(protocol, port) if err != nil { fmt.Println("Wrong Address") return } fmt.Println("Listened " + protocol + " from " + udpAddr.String()) //Create the connection udpConn, err := net.ListenUDP(protocol, udpAddr) if err != nil { fmt.Println(err) } // Listening 53 Port Like DNS Server for { // If get request, _, err := udpConn.Read(buf[0:]) if err != nil { fmt.Println("Error Reading") return } else { // Print Remote Address, // I Guess this is the Client Cache DNS IP, but this is print <nil> fmt.Println(udpConn.RemoteAddr()) } }}在这种情况下,如何获取客户端缓存 DNS IP?请帮助我,我想构建客户端 DNS IP 收集器,看起来像 whoami我也将其称为https://github.com/miekg/exdns/blob/master/reflect/reflect.go 但这不是我的答案我想要简单的服务器
1 回答

紫衣仙女
TA贡献1839条经验 获得超15个赞
UDP 是无状态的。连接没有单一的客户端地址。每个数据包都可以从不同的地址发送,因此RemoteAddr
只对客户端有用,对服务器没有用。
使用*UDPConn.ReadFrom
、*UDPConn.ReadFromUDP
或*UDPConn.ReadMsgUDP
之一代替Read
。它们都返回读取数据包的客户端地址。
- 1 回答
- 0 关注
- 153 浏览
添加回答
举报
0/150
提交
取消