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

Function scanAddress

main.go:228–331  ·  view source on GitHub ↗

实际的扫描函数

(addr string)

Source from the content-addressed store, hash-verified

226
227// 实际的扫描函数
228func scanAddress(addr string) error {
229 printInfo("正在初始化扫描...")
230
231 // 初始化地理位置查询
232 geoPaths := []string{
233 "Country.mmdb",
234 "GeoLite2-Country.mmdb",
235 "/usr/share/GeoIP/GeoLite2-Country.mmdb",
236 "/var/lib/GeoIP/GeoLite2-Country.mmdb",
237 config.Output + ".geo.mmdb",
238 }
239
240 var geo *Geo
241 var geoErr error
242 for _, path := range geoPaths {
243 if geo, geoErr = NewGeo(path); geoErr == nil {
244 printInfo(fmt.Sprintf("地理位置数据库加载成功: %s", path))
245 break
246 }
247 }
248
249 // 如果没有找到地理位置数据库,尝试自动下载
250 if geo == nil {
251 printInfo("未找到地理位置数据库,正在尝试自动下载...")
252
253 // 尝试下载到程序目录
254 downloadPath := "GeoLite2-Country.mmdb"
255 if TryDownloadGeoLite2DB(downloadPath) {
256 // 下载成功,尝试加载
257 if geo, geoErr = NewGeo(downloadPath); geoErr == nil {
258 printInfo(fmt.Sprintf("地理位置数据库下载并加载成功: %s", downloadPath))
259 } else {
260 printError(fmt.Sprintf("下载的数据库文件加载失败: %v", geoErr))
261 printInfo("将跳过地理位置查询")
262 }
263 } else {
264 printInfo("自动下载失败,将跳过地理位置查询")
265 printInfo("提示: 可手动下载 GeoLite2-Country.mmdb 文件到程序目录以启用地理位置功能")
266 }
267 }
268 defer func() {
269 if geo != nil {
270 geo.Close()
271 }
272 }()
273
274 // 解析主机
275 host, err := ParseHost(addr)
276 if err != nil {
277 return fmt.Errorf("解析地址失败: %v", err)
278 }
279
280 var hostChan <-chan Host
281 var totalTargets int
282
283 // 根据主机类型创建迭代器和计算总数
284 if host.Type == HostTypeIP {
285 // 单个IP的无限扫描模式

Callers 1

mainFunction · 0.85

Calls 11

CloseMethod · 0.95
printInfoFunction · 0.85
NewGeoFunction · 0.85
TryDownloadGeoLite2DBFunction · 0.85
printErrorFunction · 0.85
ParseHostFunction · 0.85
IterateAddrFunction · 0.85
IterateCIDRFunction · 0.85
ScanWithConcurrencyFunction · 0.85
ProcessResultsMethod · 0.80

Tested by

no test coverage detected