summaryrefslogtreecommitdiff
path: root/prober
diff options
context:
space:
mode:
authorMDK <[email protected]>2023-09-26 14:12:04 +0800
committerMDK <[email protected]>2023-09-26 14:12:04 +0800
commit4c63d78e4e42aece5e5eaa6e111e7d5fc20aabb8 (patch)
tree4341188fd10890724936b4d129ce0a958daf79c9 /prober
parent4fcf28804c88ed090d96f737db7814cce44ac1fd (diff)
the project structure modified and new features added
Diffstat (limited to 'prober')
-rw-r--r--prober/cache_prober.go8
-rw-r--r--prober/record_prober.go38
-rw-r--r--prober/result_handler.go2
-rw-r--r--prober/scheduler.go67
-rw-r--r--prober/version_prober.go1
5 files changed, 112 insertions, 4 deletions
diff --git a/prober/cache_prober.go b/prober/cache_prober.go
index b8dd9af..94adeb0 100644
--- a/prober/cache_prober.go
+++ b/prober/cache_prober.go
@@ -6,6 +6,8 @@ import (
"strconv"
"strings"
"time"
+
+ "github.com/miekg/dns"
)
const query_num = 20
@@ -15,7 +17,7 @@ type CacheStruct struct {
dict map[int]map[string]bool
}
-func RecursiveCacheProbe(ip string) CacheStruct {
+func RecursiveCacheProbe(ip string, sld string) CacheStruct {
data := CacheStruct{ip, make(map[int]map[string]bool)}
stop := 0
time_now := strconv.FormatInt(time.Now().Unix(), 10)
@@ -24,7 +26,7 @@ func RecursiveCacheProbe(ip string) CacheStruct {
break
}
subdomain := strings.Join([]string{strings.Replace(ip, ".", "-", -1), "fwd", strconv.Itoa(i), time_now}, "-")
- domain := subdomain + ".echodns.xyz."
+ domain := dns.Fqdn(subdomain + "." + sld)
res, err := utils.SendQuery(ip, domain)
if err != nil {
//fmt.Printf("Error sending query: %s\n", err)
@@ -49,7 +51,7 @@ func RecursiveCacheProbe(ip string) CacheStruct {
func RecursiveCacheTest(ip string, num int) {
res := make(map[string]map[int][]string)
temp := make(map[int][]string)
- data := RecursiveCacheProbe(ip)
+ data := RecursiveCacheProbe(ip, "echodns.xyz")
if len(data.dict) > 0 {
for cache_id := range data.dict {
for rdns := range data.dict[cache_id] {
diff --git a/prober/record_prober.go b/prober/record_prober.go
new file mode 100644
index 0000000..e976477
--- /dev/null
+++ b/prober/record_prober.go
@@ -0,0 +1,38 @@
+package prober
+
+import (
+ "dtool/utils"
+)
+
+type SVCBResult struct {
+ Ip string `json:"ip"`
+ Response utils.SVCBResponse `json:"response"`
+}
+
+func SVCBProbeOnce(ip string, domain string) (SVCBResult, error) {
+ result := SVCBResult{Ip: ip}
+ res, err := utils.SendSVCBQuery(ip, domain)
+ if err != nil {
+ return result, err
+ }
+ resp, err := utils.ParseSVCBResponse(res)
+ if err != nil {
+ return result, err
+ }
+ result.Response = resp
+ return result, nil
+}
+
+func SVCBProbe(ip string, domain string) SVCBResult {
+ result := SVCBResult{Ip: ip}
+ res, err := utils.SendSVCBQuery(ip, domain)
+ if err != nil {
+ return result
+ }
+ resp, err := utils.ParseSVCBResponse(res)
+ if err != nil {
+ return result
+ }
+ result.Response = resp
+ return result
+}
diff --git a/prober/result_handler.go b/prober/result_handler.go
index 35f85f7..470c922 100644
--- a/prober/result_handler.go
+++ b/prober/result_handler.go
@@ -26,6 +26,8 @@ func OutputHandler(data interface{}) (string, error) {
}
result[value.target] = temp
output_str, err = utils.ToJSON(result, "")
+ case SVCBResult:
+ output_str, err = utils.ToJSON(data, "")
}
return output_str, err
}
diff --git a/prober/scheduler.go b/prober/scheduler.go
new file mode 100644
index 0000000..2ffe4a2
--- /dev/null
+++ b/prober/scheduler.go
@@ -0,0 +1,67 @@
+package prober
+
+import (
+ "bufio"
+ "dtool/utils"
+ "fmt"
+ "os"
+ "sync"
+)
+
+//type ProbeTask func(string) interface{}
+
+func output_process(output chan interface{}, file string, wg *sync.WaitGroup) {
+ f, err := os.Create(file)
+ if err != nil {
+ panic(err)
+ }
+ defer f.Close()
+ writer := bufio.NewWriter(f)
+ for {
+ if data, ok := <-output; ok {
+ str, err := OutputHandler(data)
+ if err != nil {
+ fmt.Printf("Error generating output: %s\n", err)
+ continue
+ }
+ _, err = writer.WriteString(str + "\n")
+ if err != nil {
+ fmt.Printf("Error writing file: %s\n", err)
+ }
+ } else {
+ break
+ }
+ }
+ writer.Flush()
+ wg.Done()
+}
+
+func concurrent_execution[T any](fn func(string, string) T, domain string, input chan string, output chan interface{}, wg *sync.WaitGroup) {
+ for {
+ if ip, ok := <-input; ok {
+ data := fn(ip, domain)
+ output <- data
+ } else {
+ break
+ }
+ }
+ wg.Done()
+}
+
+func CreateTask[T any](fn func(string, string) T, domain string, input_file string, output_file string, concurrent_num int) {
+ input_pool := make(chan string, 500)
+ output_pool := make(chan interface{}, 500)
+ var probe_tasks sync.WaitGroup
+ var store_tasks sync.WaitGroup
+
+ go utils.RetrieveLines(input_pool, input_file)
+ probe_tasks.Add(concurrent_num)
+ for i := 0; i < concurrent_num; i++ {
+ go concurrent_execution(fn, domain, input_pool, output_pool, &probe_tasks)
+ }
+ store_tasks.Add(1)
+ go output_process(output_pool, output_file, &store_tasks)
+ probe_tasks.Wait()
+ close(output_pool)
+ store_tasks.Wait()
+}
diff --git a/prober/version_prober.go b/prober/version_prober.go
deleted file mode 100644
index 8219d21..0000000
--- a/prober/version_prober.go
+++ /dev/null
@@ -1 +0,0 @@
-package prober