programs for edns, svcb, https support measurement
This commit is contained in:
123
method/combined.go
Normal file
123
method/combined.go
Normal file
@@ -0,0 +1,123 @@
|
||||
package method
|
||||
|
||||
import (
|
||||
"edns_svcb/utils"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
type CombinedResult struct {
|
||||
Alive bool
|
||||
EDNSSupport bool
|
||||
SVCBSupport bool
|
||||
HTTPSSupport bool
|
||||
Err error
|
||||
}
|
||||
|
||||
func CombinedMeasurement(ip_pool chan string, result_pool chan CombinedResult, routine_num int, wg *sync.WaitGroup, logger *log.Logger) {
|
||||
for i := 0; i < routine_num; i++ {
|
||||
wg.Add(1)
|
||||
go CombinedTestRoutine(ip_pool, result_pool, wg, logger)
|
||||
}
|
||||
}
|
||||
|
||||
func CombinedTestRoutine(ip_pool chan string, result_pool chan CombinedResult, wg *sync.WaitGroup, logger *log.Logger) {
|
||||
for {
|
||||
if ip, ok := <-ip_pool; ok {
|
||||
addr := ip + ":53"
|
||||
res := CombinedTest(addr)
|
||||
result_pool <- res
|
||||
if res.Err != nil {
|
||||
logger.Printf("%v : failed ( %v )", ip, res.Err)
|
||||
} else {
|
||||
logger.Printf("%v : alive %v edns %v svcb %v https %v", ip, res.Alive, res.EDNSSupport, res.SVCBSupport, res.HTTPSSupport)
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
func CombinedTest(addr string) CombinedResult {
|
||||
result := CombinedResult{}
|
||||
_, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "www.example.com", RD: true})
|
||||
if err != nil {
|
||||
return CombinedResult{Err: err}
|
||||
}
|
||||
result.Alive = true
|
||||
|
||||
//edns support
|
||||
res, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "www.example.com", EDNS: true, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Extra) > 0 {
|
||||
if _, ok := res.Extra[0].(*dns.OPT); ok {
|
||||
result.EDNSSupport = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.Err = err
|
||||
return result
|
||||
}
|
||||
|
||||
// svcb support
|
||||
res, err = utils.DNSQuery(addr, utils.DNSOptions{Domain: "_dns.resolver.arpa", Qtype: dns.TypeSVCB, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Answer) > 0 {
|
||||
if _, ok := res.Answer[0].(*dns.SVCB); ok {
|
||||
result.SVCBSupport = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.Err = err
|
||||
return result
|
||||
}
|
||||
|
||||
// https support
|
||||
res, err = utils.DNSQuery(addr, utils.DNSOptions{Domain: "blog.cloudflare.com", Qtype: dns.TypeHTTPS, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Answer) > 0 {
|
||||
if _, ok := res.Answer[0].(*dns.HTTPS); ok {
|
||||
result.HTTPSSupport = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.Err = err
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func CombinedResultProcess(result_pool chan CombinedResult, wg *sync.WaitGroup) {
|
||||
alive_cnt := 0
|
||||
edns_cnt := 0
|
||||
svcb_cnt := 0
|
||||
https_cnt := 0
|
||||
for {
|
||||
if res, ok := <-result_pool; ok {
|
||||
if res.Err != nil {
|
||||
continue
|
||||
}
|
||||
if res.Alive {
|
||||
alive_cnt++
|
||||
}
|
||||
if res.EDNSSupport {
|
||||
edns_cnt++
|
||||
}
|
||||
if res.SVCBSupport {
|
||||
svcb_cnt++
|
||||
}
|
||||
if res.HTTPSSupport {
|
||||
https_cnt++
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Printf("EDNS support Test: alive %v edns %v svcb %v https %v\n", alive_cnt, edns_cnt, svcb_cnt, https_cnt)
|
||||
wg.Done()
|
||||
}
|
||||
76
method/edns.go
Normal file
76
method/edns.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package method
|
||||
|
||||
import (
|
||||
"edns_svcb/utils"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
type TestResult struct {
|
||||
Alive bool
|
||||
Support bool
|
||||
Err error
|
||||
}
|
||||
|
||||
func EDNSSupportMeasurement(ip_pool chan string, result_pool chan TestResult, routine_num int, wg *sync.WaitGroup, logger *log.Logger) {
|
||||
for i := 0; i < routine_num; i++ {
|
||||
wg.Add(1)
|
||||
go EDNSSupportTestRoutine(ip_pool, result_pool, wg, logger)
|
||||
}
|
||||
}
|
||||
|
||||
func EDNSSupportTestRoutine(ip_pool chan string, result_pool chan TestResult, wg *sync.WaitGroup, logger *log.Logger) {
|
||||
for {
|
||||
if ip, ok := <-ip_pool; ok {
|
||||
addr := ip + ":53"
|
||||
res := EDNSSupportTest(addr)
|
||||
result_pool <- res
|
||||
if res.Err != nil {
|
||||
logger.Printf("%v : failed ( %v )", ip, res.Err)
|
||||
} else {
|
||||
logger.Printf("%v : alive %v support %v", ip, res.Alive, res.Support)
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
func EDNSSupportTest(addr string) TestResult {
|
||||
_, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "www.example.net", RD: true})
|
||||
if err != nil {
|
||||
return TestResult{Err: err}
|
||||
}
|
||||
res, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "www.example.net", EDNS: true, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Extra) == 1 {
|
||||
if _, ok := res.Extra[0].(*dns.OPT); ok {
|
||||
return TestResult{Alive: true, Support: true}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TestResult{Alive: true}
|
||||
}
|
||||
|
||||
func EDNSSupportResultProcess(result_pool chan TestResult, wg *sync.WaitGroup) {
|
||||
alive_cnt := 0
|
||||
valid_cnt := 0
|
||||
for {
|
||||
if res, ok := <-result_pool; ok {
|
||||
if res.Alive {
|
||||
alive_cnt++
|
||||
}
|
||||
if res.Support {
|
||||
valid_cnt++
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Printf("EDNS support Test: alive %v support %v\n", alive_cnt, valid_cnt)
|
||||
wg.Done()
|
||||
}
|
||||
63
method/svcb.go
Normal file
63
method/svcb.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package method
|
||||
|
||||
import (
|
||||
"edns_svcb/utils"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func HTTPSSupportTest(addr string) TestResult {
|
||||
_, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "www.example.net", RD: true})
|
||||
if err != nil {
|
||||
return TestResult{Err: err}
|
||||
}
|
||||
res, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "blog.cloudflare.com", Qtype: dns.TypeHTTPS, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Answer) == 1 {
|
||||
if _, ok := res.Extra[0].(*dns.HTTPS); ok {
|
||||
return TestResult{Alive: true, Support: true}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TestResult{Alive: true}
|
||||
}
|
||||
|
||||
func SVCBSupportTest(addr string) TestResult {
|
||||
_, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "www.example.net", RD: true})
|
||||
if err != nil {
|
||||
return TestResult{Err: err}
|
||||
}
|
||||
res, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: "blog.cloudflare.com", Qtype: dns.TypeSVCB, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Answer) == 1 {
|
||||
if _, ok := res.Extra[0].(*dns.SVCB); ok {
|
||||
return TestResult{Alive: true, Support: true}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TestResult{Alive: true}
|
||||
}
|
||||
|
||||
func HTTPSRecordTest(addr, domain string) bool {
|
||||
res, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: domain, Qtype: dns.TypeHTTPS, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Answer) > 0 {
|
||||
if _, ok := res.Answer[0].(*dns.HTTPS); ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func SVCBRecordTest(addr, domain string) bool {
|
||||
res, err := utils.DNSQuery(addr, utils.DNSOptions{Domain: domain, Qtype: dns.TypeSVCB, RD: true})
|
||||
if err == nil {
|
||||
if len(res.Answer) > 0 {
|
||||
if _, ok := res.Answer[0].(*dns.SVCB); ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user