2011-01-18 02:11:11 +11:00
|
|
|
/*
|
|
|
|
* A name server which sends back the IP address of its client, the
|
|
|
|
* recursive resolver. When queried for type TXT, it sends back the text
|
|
|
|
* form of the address. When queried for type A (resp. AAAA), it sends
|
|
|
|
* back the IPv4 (resp. v6) address.
|
2011-02-12 06:54:54 +11:00
|
|
|
*
|
2011-01-18 02:11:11 +11:00
|
|
|
* Similar services: whoami.ultradns.net, whoami.akamai.net. Also (but it
|
|
|
|
* is not their normal goal): rs.dns-oarc.net, porttest.dns-oarc.net,
|
|
|
|
* amiopen.openresolvers.org.
|
2011-02-12 06:54:54 +11:00
|
|
|
*
|
2011-01-18 02:11:11 +11:00
|
|
|
* Stephane Bortzmeyer <stephane+grong@bortzmeyer.org>
|
|
|
|
*
|
|
|
|
* Adapted to Go DNS (i.e. completely rewritten)
|
|
|
|
* Miek Gieben <miek@miek.nl>
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"dns"
|
2011-02-12 07:29:40 +11:00
|
|
|
"fmt"
|
2011-07-06 00:10:49 +10:00
|
|
|
// "os"
|
|
|
|
// "os/signal"
|
|
|
|
// "strconv"
|
2011-01-18 02:11:11 +11:00
|
|
|
)
|
|
|
|
|
2011-07-05 22:58:02 +10:00
|
|
|
func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
|
2011-07-06 00:10:49 +10:00
|
|
|
m := new(dns.Msg)
|
|
|
|
m.SetReply(r)
|
|
|
|
m.Extra = make([]dns.RR, 1)
|
|
|
|
// m.Answer = make([]dns.RR, 1)
|
2011-03-22 08:59:50 +11:00
|
|
|
|
2011-07-06 00:10:49 +10:00
|
|
|
println(w.RemoteAddr())
|
|
|
|
ad := net.ParseIP(w.RemoteAddr())
|
|
|
|
println(ad.String())
|
|
|
|
// if ad.To4() != nil {
|
|
|
|
// rr := new(dns.RR_A)
|
|
|
|
// rr.Hdr = dns.RR_Header{Name: "whoami.miek.nl.", Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
|
|
|
|
// rr.A = ad
|
|
|
|
// m.Answer[0] = rr
|
|
|
|
// } else {
|
|
|
|
// r := new(dns.RR_AAAA)
|
|
|
|
// r.Hdr = dns.RR_Header{Name: "whoami.miek.nl.", Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 0}
|
|
|
|
// r.AAAA = ad
|
|
|
|
// m.Answer[0] = r
|
|
|
|
// }
|
2011-01-18 02:11:11 +11:00
|
|
|
|
2011-01-28 06:16:58 +11:00
|
|
|
t := new(dns.RR_TXT)
|
|
|
|
t.Hdr = dns.RR_Header{Name: "whoami.miek.nl.", Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}
|
2011-07-06 00:10:49 +10:00
|
|
|
// t.Txt = "Port: " + strconv.Itoa(w.RemotePort()) + " (" + w.RemoteTransport() + ")"
|
|
|
|
t.Txt = "Port: " + " (" + w.RemoteTransport() + ")"
|
2011-01-28 06:16:58 +11:00
|
|
|
m.Extra[0] = t
|
2011-01-19 07:34:22 +11:00
|
|
|
|
2011-03-22 08:53:15 +11:00
|
|
|
b, _ := m.Pack()
|
2011-07-06 00:10:49 +10:00
|
|
|
w.Write(b)
|
2011-01-18 02:11:11 +11:00
|
|
|
}
|
2011-01-19 07:34:22 +11:00
|
|
|
|
2011-02-12 06:54:54 +11:00
|
|
|
func main() {
|
2011-07-06 00:10:49 +10:00
|
|
|
dns.HandleFunc(".", handleReflect)
|
|
|
|
err := dns.ListenAndServe(":8053", "udp", nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Failed to setup the server")
|
|
|
|
}
|
2011-01-18 02:11:11 +11:00
|
|
|
}
|