修复Http扫描后ip进入黑屋子

This commit is contained in:
vanishs 2022-11-19 19:33:54 +08:00
parent f96cdb91ff
commit 7cd03923b7
4 changed files with 30 additions and 39 deletions

View File

@ -68,13 +68,13 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSe
}
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s下载测速数量%d下载测速队列%d\n", MinSpeed, TestCount, testNum)
bar := utils.NewBar(TestCount)
bar := utils.NewBar(TestCount, "", "")
for i := 0; i < testNum; i++ {
speed := downloadHandler(ipSet[i].IP)
ipSet[i].DownloadSpeed = speed
// 在每个 IP 下载测速后,以 [下载速度下限] 条件过滤结果
if speed >= MinSpeed*1024*1024 {
bar.Grow(1)
bar.Grow(1, "")
speedSet = append(speedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中
if len(speedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn就跳出循环
break

View File

@ -1,7 +1,6 @@
package task
import (
"context"
"crypto/tls"
"fmt"
"io"
@ -26,39 +25,23 @@ var (
HttpingRequest *http.Request
)
func GetRequestPort(r *http.Request) string {
port := HttpingRequest.URL.Port()
if port == "" {
if HttpingRequest.URL.Scheme == "https" {
port = "443"
} else {
port = "80"
}
}
return port
}
// pingReceived pingTotalTime
func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration) {
var fullAddress string
if isIPv4(ip.String()) {
fullAddress = fmt.Sprintf("%s", ip.String())
} else {
fullAddress = fmt.Sprintf("[%s]", ip.String())
}
hc := http.Client{
Timeout: time.Duration(HttpingTimeout) * time.Millisecond,
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
var fullAddress string
if isIPv4(ip.String()) {
fullAddress = fmt.Sprintf("%s:%s", ip.String(), GetRequestPort(HttpingRequest))
} else {
fullAddress = fmt.Sprintf("[%s]:%s", ip.String(), GetRequestPort(HttpingRequest))
}
return (&net.Dialer{}).DialContext(ctx, network, fullAddress)
},
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
} // #nosec
traceURL := fmt.Sprintf("%s://www.cloudflare.com:%s/cdn-cgi/trace",
HttpingRequest.URL.Scheme,
GetRequestPort(HttpingRequest))
traceURL := fmt.Sprintf("http://%s/cdn-cgi/trace",
fullAddress)
// for connect and get colo
{

View File

@ -4,6 +4,7 @@ import (
"fmt"
"net"
"sort"
"strconv"
"sync"
"time"
@ -54,7 +55,7 @@ func NewPing() *Ping {
ips: ips,
csv: make(utils.PingDelaySet, 0),
control: make(chan bool, Routines),
bar: utils.NewBar(len(ips)),
bar: utils.NewBar(len(ips), "Able:", ""),
}
}
@ -63,10 +64,7 @@ func (p *Ping) Run() utils.PingDelaySet {
return p.csv
}
if Httping {
fmt.Printf("开始延迟测速模式HTTP端口%s平均延迟上限%v ms平均延迟下限%v ms)\n",
GetRequestPort(HttpingRequest),
utils.InputMaxDelay.Milliseconds(),
utils.InputMinDelay.Milliseconds())
fmt.Printf("开始延迟测速模式HTTP端口80平均延迟上限%v ms平均延迟下限%v ms)\n", utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
} else {
fmt.Printf("开始延迟测速模式TCP端口%d平均延迟上限%v ms平均延迟下限%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
}
@ -131,7 +129,11 @@ func (p *Ping) appendIPData(data *utils.PingData) {
// handle tcping
func (p *Ping) tcpingHandler(ip *net.IPAddr) {
recv, totalDlay := p.checkConnection(ip)
p.bar.Grow(1)
nowAble := len(p.csv)
if recv != 0 {
nowAble++
}
p.bar.Grow(1, strconv.Itoa(nowAble))
if recv == 0 {
return
}

View File

@ -1,19 +1,25 @@
package utils
import "github.com/cheggaaa/pb/v3"
import (
"fmt"
"github.com/cheggaaa/pb/v3"
)
type Bar struct {
pb *pb.ProgressBar
}
func NewBar(count int) *Bar {
return &Bar{pb.Simple.Start(count)}
func NewBar(count int, MyStrStart, MyStrEnd string) *Bar {
tmpl := fmt.Sprintf(`{{counters . }}{{ bar . "[" "-" (cycle . "↖" "↗" "↘" "↙" ) "_" "]"}} %s {{string . "MyStr" | green}} %s `, MyStrStart, MyStrEnd)
bar := pb.ProgressBarTemplate(tmpl).Start(count)
return &Bar{pb: bar}
}
func (b *Bar) Grow(num int) {
b.pb.Add(num)
func (b *Bar) Grow(num int, MyStrVal string) {
b.pb.Set("MyStr", MyStrVal).Add(num)
}
func (b *Bar) Done() {
b.pb.Finish()
}
}