亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Go 獲取客戶端 DNS IP

如何使用 Go 獲取客戶端 DNS IP

Go
慕娘9325324 2023-03-21 14:42:33
我想使用 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。它們都返回讀取數據包的客戶端地址。


查看完整回答
反對 回復 2023-03-21
  • 1 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號