initial commit
This commit is contained in:
commit
9d6888a24a
3 changed files with 71 additions and 0 deletions
12
go.mod
Normal file
12
go.mod
Normal file
|
@ -0,0 +1,12 @@
|
|||
module gitea.snamellit.com/pti/godns
|
||||
|
||||
go 1.21.1
|
||||
|
||||
require github.com/miekg/dns v1.1.56
|
||||
|
||||
require (
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/net v0.15.0 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/tools v0.13.0 // indirect
|
||||
)
|
12
go.sum
Normal file
12
go.sum
Normal file
|
@ -0,0 +1,12 @@
|
|||
github.com/miekg/dns v1.1.56 h1:5imZaSeoRNvpM9SzWNhEcP9QliKiz20/dA2QabIGVnE=
|
||||
github.com/miekg/dns v1.1.56/go.mod h1:cRm6Oo2C8TY9ZS/TqsSrseAcncm74lfK5G+ikN2SWWY=
|
||||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
47
main.go
Normal file
47
main.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
|
||||
type DnsTest struct {
|
||||
server net.IP
|
||||
testHost string
|
||||
rtt time.Duration
|
||||
answer net.IP
|
||||
}
|
||||
|
||||
func RunTest(srv net.IP, host string) (*DnsTest, error) {
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion(host, dns.TypeA)
|
||||
c := new(dns.Client)
|
||||
in, rtt, err := c.Exchange(m, fmt.Sprintf("%s:53", srv))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, answer := range in.Answer {
|
||||
if t, ok := answer.(*dns.A); ok {
|
||||
return &DnsTest{server: srv, testHost: host, rtt: rtt, answer: t.A}, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("No answer found")
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
testHosts := []string{ "gitea.snamellit.com", "www.snamellit.com", "home.snamellit.com", "nas.snamellit.com" , "gitlab.melexis.com", "dsl.melexis.com", "cvs.tess.elex.be", "cvs.sofia.elex.be", "cvs.sensors.elex.be", "cvs.erfurt.elex.be", "www.google.com" }
|
||||
for _, host := range testHosts {
|
||||
t, err := RunTest(net.ParseIP("192.168.1.1"), host + ".")
|
||||
if err != nil {
|
||||
fmt.Println("Error for ", host, ":", err.Error())
|
||||
continue
|
||||
}
|
||||
fmt.Println("Answer ", t.server, t.testHost, t.answer, t.rtt)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue