Skip to content

we-proxy/ip-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ip-pool

See also: https://github.com/Zaeem20/FREE_PROXIES_LIST

Running Test

git clone git@github.com:we-proxy/ip-pool.git
cd ip-pool
# clone FREE_PROXIES_LIST to ./ (git-history too large, not recommended)
# git clone git@github.com:Zaeem20/FREE_PROXIES_LIST.git
# or download FREE_PROXIES_LIST (recommended)
mkdir FREE_PROXIES_LIST
curl https://fastly.jsdelivr.net/gh/Zaeem20/FREE_PROXIES_LIST@master/http.txt > FREE_PROXIES_LIST/http.txt
go test
>> ...
PASS
ok  	github.com/we-proxy/ip-pool	0.596s

Running Example

cd example
go run .
>> Response from proxy "http://135.181.154.225:80": {
  "ip": "135.181.154.225",
  "hostname": "repo.getlic.pro",
  "city": "Helsinki",
  "region": "Uusimaa",
  "country": "FI",
  "loc": "60.1695,24.9354",
  "org": "AS24940 Hetzner Online GmbH",
  "postal": "00100",
  "timezone": "Europe/Helsinki",
  "readme": "https://ipinfo.io/missingauth"
}

Import and Use

import ippool "github.com/we-proxy/ip-pool"
// ...
const random = true
const concurrent = 10
const eachTimeout = 10 * time.Second

func main() {
	// See: https://github.com/Zaeem20/FREE_PROXIES_LIST
	// proxies, err := ippool.Load("https", "path/to/https.txt") // 貌似全部阵亡
	proxies, err := ippool.Load("http", "path/to/http.txt")
	if err != nil {
		log.Println("Failed to load pool:", err)
		return
	}
	if random {
		ippool.Shuffle(proxies)
	}
	req, err := http.NewRequest("GET", "http://ipinfo.io", nil)
	if err != nil {
		log.Println("Failed to create request:", err)
		return
	}
	// v0
	// resp, proxy, err := ippool.Race(req, proxies, concurrent, eachTimeout)
	// if err != nil {
	// 	log.Println("Failed to proxy request:", err)
	// 	return
	// }
	// defer resp.Body.Close()
	// body, err := io.ReadAll(resp.Body)
	// if err != nil {
	// 	log.Println("Failed to read response:", err)
	// 	return
	// }
	// log.Printf("Response from proxy %q: %s\n", proxy, string(res))

	// v1 (latest)
	nOk := 5
	okItems, err := ippool.Race(req, proxies, concurrent, eachTimeout, nOk)
	if err != nil {
		log.Println("Failed to proxy request:", err)
		return
	}
	for i, item := range okItems {
		func() {
			defer item.Resp.Body.Close()
			log.Println("------- okItem #%d -------\n", i+1)
			body, err := io.ReadAll(item.Resp.Body)
			if err != nil {
				log.Println("Failed to read response:", err)
				return
			}
			re := regexp.MustCompile(`(?i)error|html|doctype|login|password`)
			if re.Match(body) {
				log.Printf("Response from proxy %q: not a valid IP Info\n", item.Proxy)
				return
			}
			log.Printf("Response from proxy %q: %s\n", item.Proxy, body)
		}()
	}
}

About

Go SDK to proxy with a free IP pool based on FREE_PROXIES_LIST

Topics

Resources

Stars

Watchers

Forks

Languages