Skip to content

Instantly share code, notes, and snippets.

@lanslot-choby
Created August 23, 2020 14:40
Show Gist options
  • Save lanslot-choby/02058118f6a78ed5b5134df406f3e0fd to your computer and use it in GitHub Desktop.
Save lanslot-choby/02058118f6a78ed5b5134df406f3e0fd to your computer and use it in GitHub Desktop.
DNS query through 5353 non-standard port
package main
/* DNS query through 5353 non-standard port */
import (
"time"
"github.com/miekg/dns"
"encoding/binary"
"net"
"fmt"
)
func Dnstest(target string, server string, timeout_secs int) uint32 {
c := dns.Client{Net: "udp4", Timeout: time.Duration(timeout_secs) * time.Millisecond}
m := dns.Msg{}
m.SetQuestion(target+".", dns.TypeA)
m.RecursionDesired = true
r, _, err := c.Exchange(&m, server)
if err != nil {
// fmt.Println(err)
return 0
}
// fmt.Printf("Took %v\n", t)
if len(r.Answer) == 0 {
// fmt.Println("No results")
return 0
}
for _, ans := range r.Answer {
Arecord := ans.(*dns.A)
// fmt.Printf("%s\n", Arecord.A)
return Ip2long(Arecord.A.String())
}
return 0
}
func Ip2long(ipstr string) uint32 {
ip := net.ParseIP(ipstr)
if ip == nil {
return 0
}
ip = ip.To4()
return binary.BigEndian.Uint32(ip)
}
func Do_test(Domain_str string, Srv_str string) bool {
if Dnstest(Domain_str, Srv_str, 5000) > 0 {
return true
} else {
return false
}
}
func main() {
Domain_str := "google.com"
var Title_str string
var Srv_str string
// CERTNET
Title_str = "CERTNET:"
Srv_str = "202.141.162.123:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
Srv_str = "202.38.93.153:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
fmt.Println("")
// openDNS
Title_str = "openDNS:"
Srv_str = "208.67.222.222:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
Srv_str = "208.67.220.220:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
fmt.Println("")
// AdGuard DNS
Title_str = "AdGuard DNS:"
Srv_str = "176.103.130.130:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
Srv_str = "176.103.130.131:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
Srv_str = "176.103.130.132:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
Srv_str = "176.103.130.133:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
Srv_str = "176.103.130.134:5353"
fmt.Println(Title_str, Srv_str, Do_test(Domain_str, Srv_str ) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment