Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能不能加一个参数控制每一个ip段生成的ip个数啊 #501

Closed
qwerttvv opened this issue Feb 22, 2024 · 1 comment
Closed

能不能加一个参数控制每一个ip段生成的ip个数啊 #501

qwerttvv opened this issue Feb 22, 2024 · 1 comment
Labels
功能建议 功能与建议

Comments

@qwerttvv
Copy link

功能需求

task/ip.go

更改相关代码

func (r *IPRanges) chooseIPv4() {
	if r.mask == "/32" { // 单个 IP 则无需随机,直接加入自身即可
		r.appendIP(r.firstIP)
	} else {
		minIP, hosts := r.getIPRange()    // 返回第四段 IP 的最小值及可用数目
		for i := 0; i < NumIPs; i++ { // 生成NumIPs个随机的IP地址
			for {
				newIP := minIP + randIPEndWith(hosts) // 随机 IP 的最后一段 0.0.0.X
				if _, exists := r.ips[newIP.String()]; !exists { // 如果这个IP地址还没有被添加过
					r.appendIPv4(newIP)
					break
				}
			}
		}
	}
}

func (r *IPRanges) chooseIPv6() {
	if r.mask == "/128" { // 单个 IP 则无需随机,直接加入自身即可
		r.appendIP(r.firstIP)
	} else {
		var tempIP uint8                  // 临时变量,用于记录前一位的值
		for i := 0; i < NumIPs; i++ { // 生成NumIPs个随机的IP地址
			for {
				r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
				r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段

				targetIP := make([]byte, len(r.firstIP))
				copy(targetIP, r.firstIP)
				if _, exists := r.ips[targetIP.String()]; !exists { // 如果这个IP地址还没有被添加过
					r.appendIP(targetIP) // 加入 IP 地址池
					break
				}
			}
		}
	}
}

main.go加个参数什么-ips或者其它别的表述下啥的?

预期目标

自己控制一个段几个ip参与测试

@qwerttvv qwerttvv added the 功能建议 功能与建议 label Feb 22, 2024
@qwerttvv
Copy link
Author

因为有的段的ip整体比较快,有些下载软件会从dns返回的不同的ip分别下载,这样就可以多来几个线程在快的段的服务器

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
功能建议 功能与建议
Projects
None yet
Development

No branches or pull requests

1 participant