MCPcopy Index your code
hub / github.com/MengMengCode/GetRealityDomain / IterateAddr

Function IterateAddr

utils.go:193–252  ·  view source on GitHub ↗

IterateAddr 无限扫描模式,从指定IP开始向上下扩展

(addr string)

Source from the content-addressed store, hash-verified

191
192// IterateAddr 无限扫描模式,从指定IP开始向上下扩展
193func IterateAddr(addr string) <-chan Host {
194 hostChan := make(chan Host, 100)
195
196 go func() {
197 defer close(hostChan)
198
199 // 解析初始IP
200 initialIP := net.ParseIP(addr)
201 if initialIP == nil {
202 printError(fmt.Sprintf("无效的IP地址: %s", addr))
203 return
204 }
205
206 // 发送初始IP
207 hostChan <- Host{
208 IP: initialIP,
209 Origin: addr,
210 Type: HostTypeIP,
211 }
212
213 // 设置上下扩展的IP
214 lowIP := make(net.IP, len(initialIP))
215 highIP := make(net.IP, len(initialIP))
216 copy(lowIP, initialIP)
217 copy(highIP, initialIP)
218
219 // 交替向上下扩展
220 for i := 0; i < math.MaxInt; i++ {
221 if i%2 == 0 {
222 // 向下扩展
223 lowIP = NextIP(lowIP, false)
224 if !isValidIP(lowIP) {
225 continue
226 }
227 newLowHost := Host{
228 IP: make(net.IP, len(lowIP)),
229 Origin: addr,
230 Type: HostTypeIP,
231 }
232 copy(newLowHost.IP, lowIP)
233 hostChan <- newLowHost
234 } else {
235 // 向上扩展
236 highIP = NextIP(highIP, true)
237 if !isValidIP(highIP) {
238 continue
239 }
240 newHighHost := Host{
241 IP: make(net.IP, len(highIP)),
242 Origin: addr,
243 Type: HostTypeIP,
244 }
245 copy(newHighHost.IP, highIP)
246 hostChan <- newHighHost
247 }
248 }
249 }()
250

Callers 1

scanAddressFunction · 0.85

Calls 3

printErrorFunction · 0.85
NextIPFunction · 0.85
isValidIPFunction · 0.85

Tested by

no test coverage detected