()
| 61 | } |
| 62 | } |
| 63 | func (s *KSubDomainSensor) GetResult() Result { |
| 64 | s.result = Result{} |
| 65 | if s.Type != "subdomain" { |
| 66 | return s.result |
| 67 | } |
| 68 | s.AddTask() |
| 69 | ksubdomain.LocalStack = ksubdomain.NewStack() |
| 70 | ksubdomain.ResultObj.Length = len(s.Tasks) |
| 71 | var rate int64 |
| 72 | rate = 1000 |
| 73 | // 获取网卡 |
| 74 | ether := ksubdomain.AutoGetDevices() |
| 75 | // packet 标识符 |
| 76 | flagID := uint16(ksubdomain.RandInt64(400, 654)) |
| 77 | // 用于重试的chan |
| 78 | retryChan := make(chan ksubdomain.RetryStruct, rate) |
| 79 | go ksubdomain.Recv(ether.Device, flagID, retryChan) |
| 80 | sendog := ksubdomain.SendDog{} |
| 81 | sendog.Init(ether, []string{"223.5.5.5", "223.6.6.6", "180.76.76.76", "119.29.29.29", "178.79.131.110", "199.91.73.222", "185.184.222.222", "185.222.222.222", "182.254.116.116", "140.207.198.6", "123.125.81.6", "114.114.114.115", "218.30.118.6", "101.226.4.6"}, flagID, true) |
| 82 | limiter := rateLimit.NewLimiter(rateLimit.Every(time.Duration(time.Second.Nanoseconds()/rate)), int(rate)) |
| 83 | ctx := context.Background() |
| 84 | |
| 85 | // 协程重发检测 |
| 86 | go func() { |
| 87 | for { |
| 88 | // 循环检测超时的队列 |
| 89 | maxLength := int(rate / 10) |
| 90 | datas := ksubdomain.LocalStauts.GetTimeoutData(maxLength) |
| 91 | isdelay := true |
| 92 | if len(datas) <= 100 { |
| 93 | isdelay = false |
| 94 | } |
| 95 | for _, localdata := range datas { |
| 96 | index := localdata.Index |
| 97 | value := localdata.V |
| 98 | if value.Retry >= 15 { |
| 99 | atomic.AddUint64(&ksubdomain.FaildIndex, 1) |
| 100 | ksubdomain.LocalStauts.SearchFromIndexAndDelete(index) |
| 101 | continue |
| 102 | } |
| 103 | _ = limiter.Wait(ctx) |
| 104 | value.Retry++ |
| 105 | value.Time = time.Now().Unix() |
| 106 | value.Dns = sendog.ChoseDns() |
| 107 | // 先删除,再重新创建 |
| 108 | ksubdomain.LocalStauts.SearchFromIndexAndDelete(index) |
| 109 | ksubdomain.LocalStauts.Append(&value, index) |
| 110 | flag2, srcport := ksubdomain.GenerateFlagIndexFromMap(index) |
| 111 | retryChan <- ksubdomain.RetryStruct{Domain: value.Domain, Dns: value.Dns, SrcPort: srcport, FlagId: flag2, DomainLevel: value.DomainLevel} |
| 112 | if isdelay { |
| 113 | time.Sleep(time.Microsecond * time.Duration(rand.Intn(300)+100)) |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | }() |
| 118 | // 多级域名检测 |
| 119 | go func() { |
| 120 | for { |
nothing calls this directly
no test coverage detected