Skip to content

Commit

Permalink
Merge pull request #23 from Kuucheen/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Kuucheen authored Oct 27, 2024
2 parents dfa3515 + 80e46a8 commit 42308b9
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 46 deletions.
4 changes: 3 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ Now you have an executable. You can run it like described in **Getting Started**
Timeout duration of judges in ms

12. **judges**: <br>
These websites are the sites the proxies will connect to. These have to return the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers">headers</a> of the request so the checker can determine what anonymity level the proxy is.
**url**: This is the url the proxy will connect to while checking <br>
**regex**: The proxy will only be valid if the regex is found. When "default" is used it will check the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers">headers</a>. Headers are needed to determine the anonymity level of the proxies. <br>
If there are multiple judges the checker will use the fastest one

13. **blacklisted**:<br>
Websites that contain blacklisted ips. These ips won't be checked
Expand Down
2 changes: 1 addition & 1 deletion charm/hosts/loading_display.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (m model) View() string {

if len(data) == 0 {
for _, val := range common.GetConfig().Judges {
data[val] = "?"
data[val.Url] = "?"
}
}

Expand Down
63 changes: 46 additions & 17 deletions common/judges.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/http"
"net/url"
"regexp"
"sort"
"strings"
"sync"
Expand All @@ -15,19 +16,22 @@ import (
type JudgesTimes struct {
Judge string
Ip string
Regex string
ResponseTime time.Duration
}

type HostTimes []JudgesTimes

var (
UserIP string
FastestJudge string
FastestJudgeName *url.URL
FastestJudges map[string]string
FastestJudgesName map[string]*url.URL

standardHeader = []string{"HTTP_HOST", "REQUEST_METHOD", "REMOTE_ADDR", "REMOTE_PORT"}
UserIP string
FastestJudge string
FastestJudgeName *url.URL
FastestJudgeRegex string
FastestJudges map[string]string
FastestJudgesName map[string]*url.URL
FastestJudgesRegex map[string]string

standardHeader = []string{"USER-AGENT", "HOST", "ACCEPT", "ACCEPT-ENCODING", "ACCEPT-ENCODING"}
)

func (ht HostTimes) Len() int {
Expand All @@ -52,6 +56,7 @@ var (
func CheckDomains() HostTimes {
FastestJudges = make(map[string]string)
FastestJudgesName = make(map[string]*url.URL)
FastestJudgesRegex = make(map[string]string)

configHosts := GetConfig().Judges
maxThreads := GetConfig().JudgesThreads
Expand All @@ -77,6 +82,7 @@ func CheckDomains() HostTimes {
sort.Sort(CurrentCheckedHosts)

FastestJudge = CurrentCheckedHosts[0].Ip
FastestJudgeRegex = CurrentCheckedHosts[0].Regex

u, err := url.Parse(CurrentCheckedHosts[0].Judge)
if err == nil {
Expand All @@ -91,6 +97,7 @@ func CheckDomains() HostTimes {

if !ok {
FastestJudges[protocol] = host.Ip
FastestJudgesRegex[protocol] = host.Regex
}

_, ok = FastestJudgesName[protocol]
Expand All @@ -107,14 +114,15 @@ func CheckDomains() HostTimes {
return unsortedHosts
}

func checkTimeAsync(host string) {
func checkTimeAsync(host configJudge) {
defer wg.Done()
defer atomic.AddInt32(&currentThreads, -1)

ip, responseTime := checkTime(host)
ip, responseTime := checkTime(host.Url, host.Regex)
hostTime := JudgesTimes{
Judge: host,
Judge: host.Url,
Ip: ip,
Regex: host.Regex,
ResponseTime: responseTime,
}

Expand All @@ -124,7 +132,7 @@ func checkTimeAsync(host string) {
}

// Main function to check the time
func checkTime(host string) (string, time.Duration) {
func checkTime(host string, regex string) (string, time.Duration) {
// Parse the URL to extract the hostname
parsedURL, err := url.Parse(host)
if err != nil {
Expand Down Expand Up @@ -165,7 +173,7 @@ func checkTime(host string) (string, time.Duration) {
return ip, time.Hour * 999
}

if !CheckForValidResponse(string(resBody)) {
if !CheckForValidResponse(string(resBody), regex) {
return ip, time.Hour * 99
}

Expand Down Expand Up @@ -212,12 +220,33 @@ func GetFastestJudgeNameForProtocol(protocol string) *url.URL {
return FastestJudgesName[protocol]
}

func CheckForValidResponse(html string) bool {
for _, header := range standardHeader {
if !strings.Contains(html, header) {
return false
func GetFastestJudgeRegexForProtocol(protocol string) string {
if strings.HasPrefix(protocol, "socks") {
return FastestJudgeRegex
}

return FastestJudgesRegex[protocol]
}

func CheckForValidResponse(html string, regex string) bool {
if strings.EqualFold(regex, "default") {
html = strings.ReplaceAll(html, "_", "-")
html = strings.ToUpper(html)

for _, header := range standardHeader {
if !strings.Contains(html, header) {

return false
}
}

return true
}

re, err := regexp.Compile(regex)
if err != nil {
return false
}

return true
return re.MatchString(html)
}
46 changes: 25 additions & 21 deletions common/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import (
)

type Config struct {
Threads int `json:"threads"`
Retries int `json:"retries"`
Timeout int `json:"timeout"`
PrivacyMode bool `json:"privacy_mode"`
CopyToClipboard bool `json:"copyToClipboard"`
AutoSelect autoSelect `json:"autoSelect"`
AutoOutput autoSave `json:"autoSave"`
TimeBetweenRefresh int `json:"timeBetweenRefresh"`
IpLookup string `json:"iplookup"`
JudgesThreads int `json:"judges_threads"`
JudgesTimeOut int `json:"judges_timeout"`
Judges []string `json:"judges"`
Blacklisted []string `json:"blacklisted"`
Bancheck string `json:"bancheck"`
Keywords []string `json:"keywords"`
Transport transport `json:"transport"`
Threads int `json:"threads"`
Retries int `json:"retries"`
Timeout int `json:"timeout"`
PrivacyMode bool `json:"privacy_mode"`
CopyToClipboard bool `json:"copyToClipboard"`
AutoSelect autoSelect `json:"autoSelect"`
AutoOutput autoSave `json:"autoSave"`
TimeBetweenRefresh int `json:"timeBetweenRefresh"`
IpLookup string `json:"iplookup"`
JudgesThreads int `json:"judges_threads"`
JudgesTimeOut int `json:"judges_timeout"`
Judges []configJudge `json:"judges"`
Blacklisted []string `json:"blacklisted"`
Bancheck string `json:"bancheck"`
Keywords []string `json:"keywords"`
Transport transport `json:"transport"`
}

type autoSelect struct {
Expand Down Expand Up @@ -52,6 +52,11 @@ type transport struct {
ExpectContinueTimeout int `json:"ExpectContinueTimeout"`
}

type configJudge struct {
Url string `json:"url"`
Regex string `json:"regex"`
}

var config Config

func ReadSettings() {
Expand All @@ -78,11 +83,11 @@ func RemoveHttpsJudges() {
}

func removeJudge(str string) {
var httpsJudges []string
var httpsJudges []configJudge

for _, i2 := range config.Judges {
if strings.HasPrefix(i2, str) {
httpsJudges = append(httpsJudges, i2)
if strings.HasPrefix(i2.Url, str) {
httpsJudges = append(httpsJudges, configJudge{Url: i2.Url, Regex: i2.Regex})
}
}

Expand Down Expand Up @@ -114,12 +119,11 @@ func DoBanCheck() bool {
}

func IsAllowedToCheck(typeNames []string) bool {

for _, name := range typeNames {
hasBeenFound := false

for _, judge := range config.Judges {
if strings.HasPrefix(judge, name) {
if strings.HasPrefix(judge.Url, name) {
hasBeenFound = true
break
}
Expand Down
6 changes: 3 additions & 3 deletions helper/checker_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func GetProxyLevel(html string) int {
}

func Request(proxy *Proxy) (string, int, error) {
return RequestCustom(proxy, common.GetFastestJudgeForProtocol(proxy.Protocol), common.GetFastestJudgeNameForProtocol(proxy.Protocol), false)
return RequestCustom(proxy, common.GetFastestJudgeForProtocol(proxy.Protocol), common.GetFastestJudgeNameForProtocol(proxy.Protocol), common.GetFastestJudgeRegexForProtocol(proxy.Protocol), false)
}

// RequestCustom makes a request to the provided siteUrl with the provided proxy
func RequestCustom(proxyToCheck *Proxy, targetIp string, siteName *url.URL, isBanCheck bool) (string, int, error) {
func RequestCustom(proxyToCheck *Proxy, targetIp string, siteName *url.URL, regex string, isBanCheck bool) (string, int, error) {
proxyURL, err := url.Parse(strings.Replace(proxyToCheck.Protocol, "https", "http", 1) + "://" + proxyToCheck.Full)
if err != nil {
return "Error parsing proxyToCheck URL", -1, err
Expand Down Expand Up @@ -102,7 +102,7 @@ func RequestCustom(proxyToCheck *Proxy, targetIp string, siteName *url.URL, isBa
}

html := string(resBody)
if !isBanCheck && !common.CheckForValidResponse(html) {
if !isBanCheck && !common.CheckForValidResponse(html, regex) {
return "Invalid response", -1, nil
}

Expand Down
2 changes: 1 addition & 1 deletion helper/thread_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func check(proxy *Proxy) {
if responded && common.DoBanCheck() && err == nil {

for i := 0; i < retries; i++ {
body, status, err := RequestCustom(proxy, common.GetConfig().Bancheck, u, true)
body, status, err := RequestCustom(proxy, common.GetConfig().Bancheck, u, "", true)
IncrementCheckCount()

if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"KC-Checker/common"
"KC-Checker/helper"
"github.com/jwalton/go-supportscolor"
"runtime/debug"
)

func main() {
//Lets the terminal on Windows 10 support true color
supportscolor.Stdout()

debug.SetMaxThreads(999999999)

common.ReadSettings()

common.GetLocalIP()
Expand Down
7 changes: 5 additions & 2 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
"judges_threads": 3,
"judges_timeout": 5000,
"judges": [
"http://azenv.net",
"https://pool.proxyspace.pro/judge.php"
{"url": "http://azenv.net", "regex": "default"},
{"url": "http://httpbin.org/headers", "regex": "default"},
{"url": "https://pool.proxyspace.pro/judge.php", "regex": "default"},
{"url": "https://httpbingo.org/headers", "regex": "default"},
{"url": "https://postman-echo.com/headers", "regex": "default"}
],

"blacklisted": [
Expand Down

0 comments on commit 42308b9

Please sign in to comment.