mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-04-21 05:36:27 +08:00
replace ipv6 repeat code
This commit is contained in:
80
task/ip.go
80
task/ip.go
@@ -2,7 +2,6 @@ package task
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
@@ -94,7 +93,6 @@ func (r *IPRanges) getIPRange() (minIP, hosts byte) {
|
|||||||
|
|
||||||
func (r *IPRanges) chooseIPv4() {
|
func (r *IPRanges) chooseIPv4() {
|
||||||
minIP, hosts := r.getIPRange()
|
minIP, hosts := r.getIPRange()
|
||||||
fmt.Println(minIP, hosts)
|
|
||||||
for r.ipNet.Contains(r.firstIP) {
|
for r.ipNet.Contains(r.firstIP) {
|
||||||
if TestAll { // 如果是测速全部 IP
|
if TestAll { // 如果是测速全部 IP
|
||||||
for i := byte(0); i <= hosts; i++ { // 遍历 IP 最后一段最小值到最大值
|
for i := byte(0); i <= hosts; i++ { // 遍历 IP 最后一段最小值到最大值
|
||||||
@@ -122,76 +120,16 @@ func (r *IPRanges) chooseIPv6() {
|
|||||||
r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
|
r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||||
r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段
|
r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||||
}
|
}
|
||||||
firstIPCopy := make([]byte, len(r.firstIP))
|
targetIP := make([]byte, len(r.firstIP))
|
||||||
copy(firstIPCopy, r.firstIP)
|
copy(targetIP, r.firstIP)
|
||||||
r.appendIP(firstIPCopy)
|
r.appendIP(targetIP)
|
||||||
tempIP = r.firstIP[13]
|
for i := 13; i >= 0; i-- {
|
||||||
r.firstIP[13] += randIPEndWith(255)
|
tempIP = r.firstIP[i]
|
||||||
if r.firstIP[13] >= tempIP {
|
r.firstIP[i] += randIPEndWith(255)
|
||||||
continue
|
if r.firstIP[i] >= tempIP {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tempIP = r.firstIP[12]
|
|
||||||
r.firstIP[12] += randIPEndWith(255)
|
|
||||||
if r.firstIP[12] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[11]
|
|
||||||
r.firstIP[11] += randIPEndWith(255)
|
|
||||||
if r.firstIP[11] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[10]
|
|
||||||
r.firstIP[10] += randIPEndWith(255)
|
|
||||||
if r.firstIP[10] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[9]
|
|
||||||
r.firstIP[9] += randIPEndWith(255)
|
|
||||||
if r.firstIP[9] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[8]
|
|
||||||
r.firstIP[8] += randIPEndWith(255)
|
|
||||||
if r.firstIP[8] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[7]
|
|
||||||
r.firstIP[7] += randIPEndWith(255)
|
|
||||||
if r.firstIP[7] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[6]
|
|
||||||
r.firstIP[6] += randIPEndWith(255)
|
|
||||||
if r.firstIP[6] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[5]
|
|
||||||
r.firstIP[5] += randIPEndWith(255)
|
|
||||||
if r.firstIP[5] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[4]
|
|
||||||
r.firstIP[4] += randIPEndWith(255)
|
|
||||||
if r.firstIP[4] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[3]
|
|
||||||
r.firstIP[3] += randIPEndWith(255)
|
|
||||||
if r.firstIP[3] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[2]
|
|
||||||
r.firstIP[2] += randIPEndWith(255)
|
|
||||||
if r.firstIP[2] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[1]
|
|
||||||
r.firstIP[1] += randIPEndWith(255)
|
|
||||||
if r.firstIP[1] >= tempIP {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tempIP = r.firstIP[0]
|
|
||||||
r.firstIP[0] += randIPEndWith(255)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user