mmpx12 / proxy-check

Check if proxies (http, socks4, socks5) are working.
89 stars 13 forks source link

Enhancement - Check for custom response keyword and check all proxys without protocol #2

Closed Beykir closed 1 year ago

Beykir commented 1 year ago

Hey,

can you please add the argument, to check a custom website with a custom keyword in response text? For example: https://google.com if "google" in response text proxy is valid.

And my second enhancement would be, to check proxys even without a protocol tag like http://, socks4:// or socks5:// something like

for protocol in ["http://", "socks4://", "socks5://"]: ... and then save valid http proxys in http.txt, valid socks4 in socks4.txt and valid socks5 in socks5.txt

mmpx12 commented 1 year ago

@Beykir I can do the first two:

But for the last one i will not implement this, just do a simple bash loop for that:

for i in {"http", "socks4","socks5"}; do
  grep --color=never -E "^$i" output.txt >> $i.txt
done

But for string in response should it test in headers, body or both ?

Beykir commented 1 year ago

for me personally body would be enough, i think its the safest variant, to be sure the proxy is 100% valid

mmpx12 commented 1 year ago

@Beykir

I had the -i|--ip flag in v1.1.1: if set and if ip don't have proto it will test for http, socks4& socks5.

However i will not add body searching . It will slow down too much the result. But fell free to fork, here is how to do ( i dint try but it should work):

+++ b/proxy-check.go
@@ -4,6 +4,7 @@ import (
    "bufio"
    "context"
    "fmt"
+   "io"
    "math/rand"
    "net/http"
    URL "net/url"
@@ -21,17 +22,18 @@ import (
 )

 var (
-   Proxies    []string
-   mu         = &sync.Mutex{}
-   valid      []string
-   checkmax   bool
-   counter    int32
-   maxvalid   int
-   disableBar bool
-   noProto    bool
-   delete     bool
-   file       string
-   version    = "1.1.1"
+   Proxies      []string
+   mu           = &sync.Mutex{}
+   valid        []string
+   checkmax     bool
+   counter      int32
+   maxvalid     int
+   disableBar   bool
+   searchString string
+   noProto      bool
+   delete       bool
+   file         string
+   version      = "1.1.1"
 )

 func ProxyTest(client *http.Client, proxy, urlTarget, timeout string) bool {
@@ -60,6 +62,16 @@ func ProxyTest(client *http.Client, proxy, urlTarget, timeout string) bool {
    }

    if resp.StatusCode != http.StatusOK {
+       if searchString != "" {
+           body, err := io.ReadAll(resp.Body)
+           if err != nil {
+               return
+           }
+           match, err := regexp.MatchString(searchString, string(body))
+           if err != nil {
+               return
+           }
+       }
        if disableBar {
            fmt.Println("\033[31m[X] ", proxy, "\033[0m")
        }
@@ -134,6 +146,7 @@ func main() {
    op.On("-H", "--http", "Test http proxies", &httpp)
    op.On("-r", "--randomize-file", "Shuffle proxies files", &random)
    op.On("-t", "--thread NBR", "Number of threads", &goroutine)
+   op.On("-z", "--search STR", "Search for string", &searchString)
    op.On("-T", "--timeout SEC", "Set timeout (seconds)", &timeout)
    op.On("-u", "--url TARGET", "set URL for testing proxies", &url)
    op.On("-f", "--proxies-file FILE", "files with proxies (proto://ip:port)", &file)

Wasn't in good place:

--- a/proxy-check.go
+++ b/proxy-check.go
@@ -62,16 +62,7 @@ func ProxyTest(client *http.Client, proxy, urlTarget, timeout string) bool {
    }

    if resp.StatusCode != http.StatusOK {
-       if searchString != "" {
-           body, err := io.ReadAll(resp.Body)
-           if err != nil {
-               return
-           }
-           match, err := regexp.MatchString(searchString, string(body))
-           if err != nil {
-               return
-           }
-       }
+
        if disableBar {
            fmt.Println("\033[31m[X] ", proxy, "\033[0m")
        }
(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -80,6 +71,16 @@ func ProxyTest(client *http.Client, proxy, urlTarget, timeout string) bool {
    if disableBar {
        fmt.Println("\033[32m[√] ", proxy, "\033[0m")
    }
+   if searchString != "" {
+       body, err := io.ReadAll(resp.Body)
+       if err != nil {
+           return false
+       }
+       match, err := regexp.MatchString(searchString, string(body))
+       if err != nil {
+           return false
+       }
+   }
    mu.Lock()
    valid = append(valid, proxy)
    mu.Unlock()
Beykir commented 1 year ago

@mmpx12

However i will not add body searching . It will slow down too much the result.

I'm still using your proxychecker tool from time to time 👍

Today i asked myself if it would be faster to read the response line by line like this:

package main

import (
   "log"
   "net/http"
   "fmt"
   "bufio"
   "strings"
)

func main() {
   resp, err := http.Get("https://google.com")
   if err != nil {
      log.Fatalln(err)
   }
   reader := bufio.NewReader(resp.Body)
   doThis := true
   for doThis {
       lb, err := reader.ReadBytes('\n')
       if err != nil {
           doThis = false
           log.Fatalln(err)
        } else {
            fmt.Printf("\nGot some data:\n\t%v", string(lb))
            if strings.Contains(string(lb), "user") {
                break
            }
        }
   }
}

What do you say?

mmpx12 commented 1 year ago

@Beykir Do a pull request with the change.