kayos@tcp.direct
c24756973e
fixes: --- go: endless/internal/moonproxy imports git.tcp.direct/moony/endless/internal/moonproxy: git.tcp.direct/moony/endless@v0.0.0-20230317092824-035eb62124ec: parsing go.mod: module declares its path as: endless but was required as: git.tcp.direct/moony/endless
83 lines
1.6 KiB
Go
83 lines
1.6 KiB
Go
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.tcp.direct/moony/endless/internal/utils"
|
|
|
|
"h12.io/socks"
|
|
)
|
|
|
|
func GetHttpTransport(Proxy string) *http.Transport {
|
|
ProxyUrl, err := url.Parse(Proxy)
|
|
if utils.HandleError(err) {
|
|
return &http.Transport{}
|
|
}
|
|
|
|
return &http.Transport{
|
|
Proxy: http.ProxyURL(ProxyUrl),
|
|
}
|
|
}
|
|
|
|
func GetSocksTranport(Proxy string) *http.Transport {
|
|
return &http.Transport{
|
|
Dial: socks.Dial(fmt.Sprintf("%s?timeout=%ds", Proxy, utils.Config.Filter.Timeout)),
|
|
}
|
|
}
|
|
|
|
func GetTransport(Proxy string) *http.Transport {
|
|
if strings.Contains(Proxy, "http://") {
|
|
return GetHttpTransport(Proxy)
|
|
} else {
|
|
return GetSocksTranport(Proxy)
|
|
}
|
|
}
|
|
|
|
func ProxyReq(req string, proxy string) (res *http.Response, err error) {
|
|
ReqUrl, err := url.Parse(req)
|
|
if utils.HandleError(err) {
|
|
return nil, err
|
|
}
|
|
|
|
client := &http.Client{
|
|
Timeout: time.Duration(time.Duration(utils.Config.Filter.Timeout) * time.Second),
|
|
Transport: GetTransport(proxy),
|
|
}
|
|
|
|
res, err = client.Get(ReqUrl.String())
|
|
return res, err
|
|
}
|
|
|
|
func CheckProxy(Proxy string) {
|
|
response, err := ProxyReq("https://api.ipify.org", Proxy)
|
|
if err != nil {
|
|
if utils.Config.Options.ShowDeadProxies {
|
|
utils.Log(fmt.Sprintf("[x] [DEAD] [%s]", Proxy))
|
|
}
|
|
return
|
|
}
|
|
|
|
defer response.Body.Close()
|
|
|
|
content, err := ioutil.ReadAll(response.Body)
|
|
if utils.HandleError(err) {
|
|
return
|
|
}
|
|
|
|
is_elite := string(content) != utils.ActualIp
|
|
|
|
utils.Log(fmt.Sprintf("[!] [ALIVE] [ELITE: %v] [%s]", is_elite, Proxy))
|
|
utils.Valid++
|
|
|
|
if !is_elite && !utils.Config.Options.SaveTransparent {
|
|
return
|
|
}
|
|
|
|
utils.AppendFile("checked.txt", Proxy)
|
|
}
|