the project structure modified and new features added
This commit is contained in:
@@ -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] {
|
||||
|
||||
38
prober/record_prober.go
Normal file
38
prober/record_prober.go
Normal file
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
67
prober/scheduler.go
Normal file
67
prober/scheduler.go
Normal file
@@ -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()
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package prober
|
||||
Reference in New Issue
Block a user