func dnsHandler(w dns.ResponseWriter, r *dns.Msg) { msg := &dns.Msg{} msg.SetReply(r) msg.Authoritative = true msg.Answer = []dns.RR{&dns.A{ Header: dns.RR_Header{Name: r.Question[0].Name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600}, A: net.IPv4(127, 0, 0, 1), }} w.WriteMsg(msg) }
func handler(w http.ResponseWriter, r *http.Request) { ip := r.RemoteAddr fmt.Fprintln(w, "Your IP address is", ip) }This function handles incoming HTTP requests and uses the RemoteAddr field of the Request type to get the IP address of the remote client. In conclusion, the go library being used is "github.com/miekg/dns" and the examples above demonstrate the usage of ResponseWriter for handling DNS server responses and RemoteAddr for getting the IP address of remote clients.