the project structure modified and new features added
This commit is contained in:
@@ -27,6 +27,15 @@ type DomainInfo struct {
|
||||
NSList map[string][]string
|
||||
}
|
||||
|
||||
type SVCBRecord struct {
|
||||
Target string `json:"target"`
|
||||
Data map[string]string `json:"value"`
|
||||
}
|
||||
|
||||
type SVCBResponse struct {
|
||||
Records []SVCBRecord `json:"records"`
|
||||
}
|
||||
|
||||
func (e *WrongAnswerError) Error() string {
|
||||
return fmt.Sprintf("Wrong Answer: %s", e.Message)
|
||||
}
|
||||
@@ -39,11 +48,7 @@ func QuestionMaker(domain string, qclass uint16, qtype uint16) *dns.Question {
|
||||
// build a dns query message
|
||||
func QueryMaker(query QueryStruct) *dns.Msg {
|
||||
msg := new(dns.Msg)
|
||||
if query.Id < 0 {
|
||||
msg.Id = dns.Id()
|
||||
} else {
|
||||
msg.Id = query.Id
|
||||
}
|
||||
msg.Id = query.Id
|
||||
msg.RecursionDesired = query.RD
|
||||
|
||||
var query_name string
|
||||
@@ -155,3 +160,58 @@ func SendVersionQuery(ip string) (*dns.Msg, error) {
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
func SendSVCBQuery(ip string, domain string) (*dns.Msg, error) {
|
||||
addr := ip + ":53"
|
||||
query := QueryStruct{Id: dns.Id(), Qname: dns.Fqdn(domain), RD: true, Qtype: dns.TypeSVCB}
|
||||
m := QueryMaker(query)
|
||||
|
||||
res, err := dns.Exchange(m, addr)
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
func toSVCBKEY(key dns.SVCBKey) string {
|
||||
switch key {
|
||||
case dns.SVCB_MANDATORY:
|
||||
return "mandatory"
|
||||
case dns.SVCB_ALPN:
|
||||
return "alpn"
|
||||
case dns.SVCB_NO_DEFAULT_ALPN:
|
||||
return "no_default_alpn"
|
||||
case dns.SVCB_PORT:
|
||||
return "port"
|
||||
case dns.SVCB_IPV4HINT:
|
||||
return "ipv4_hint"
|
||||
case dns.SVCB_ECHCONFIG:
|
||||
return "ech_config"
|
||||
case dns.SVCB_IPV6HINT:
|
||||
return "ipv6_hint"
|
||||
case dns.SVCB_DOHPATH:
|
||||
return "doh_path"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func ParseSVCBResponse(msg *dns.Msg) (SVCBResponse, error) {
|
||||
response := SVCBResponse{Records: make([]SVCBRecord, 0)}
|
||||
if len(msg.Answer) > 0 {
|
||||
for _, rr := range msg.Answer {
|
||||
if svcb, ok := rr.(*dns.SVCB); ok {
|
||||
record := SVCBRecord{Data: make(map[string]string)}
|
||||
record.Target = svcb.Target
|
||||
for _, kv := range svcb.Value {
|
||||
key := toSVCBKEY(kv.Key())
|
||||
value := kv.String()
|
||||
record.Data[key] = value
|
||||
}
|
||||
response.Records = append(response.Records, record)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(response.Records) > 0 {
|
||||
return response, nil
|
||||
}
|
||||
return response, &WrongAnswerError{Message: "no valid SVCB records"}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"crypto/des"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -75,7 +75,7 @@ func SendTencentHttpdnsQuery() {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Printf("read content failed. Error: %s\n", err)
|
||||
return
|
||||
@@ -102,7 +102,7 @@ func SendAlicloudHttpdnsQurey() {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Printf("read content failed. Error: %s\n", err)
|
||||
return
|
||||
|
||||
@@ -24,7 +24,7 @@ func RetrieveLines(pool chan string, filename string) {
|
||||
s = strings.Trim(s, "\n")
|
||||
pool <- s
|
||||
cnt++
|
||||
if cnt%10 == 0 {
|
||||
if cnt%1000 == 0 {
|
||||
fmt.Println(cnt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,5 @@ import (
|
||||
|
||||
func IsValidIP(ip string) bool {
|
||||
res := net.ParseIP(ip)
|
||||
if res == nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return res != nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user