prox5/list_management.go

96 lines
1.9 KiB
Go
Raw Normal View History

package pxndscvm
import (
"bufio"
"os"
"strconv"
"strings"
ipa "inet.af/netaddr"
)
2021-09-20 01:23:18 +00:00
// throw shit proxies here, get map
var inChan chan string
func init() {
inChan = make(chan string, 100)
}
func (s *Swamp) stage1(in string) bool {
if !strings.Contains(in, ":") {
return false
}
split := strings.Split(in, ":")
if _, err := ipa.ParseIP(split[0]); err != nil {
return false
}
if _, err := strconv.Atoi(in); err != nil {
return false
}
s.mu.RLock()
if _, ok := s.swampmap[in]; ok {
s.mu.RUnlock()
return false
}
s.mu.RUnlock()
return true
}
// LoadProxyTXT loads proxies from a given seed file and randomly feeds them to the workers.
2021-09-20 01:23:18 +00:00
func (s *Swamp) LoadProxyTXT(seedFile string) int {
var count int
s.dbgPrint("LoadProxyTXT start: "+seedFile)
defer s.dbgPrint("LoadProxyTXT finished: " + strconv.Itoa(count))
f, err := os.Open(seedFile)
if err != nil {
2021-09-20 01:23:18 +00:00
panic(err)
return 0
}
scan := bufio.NewScanner(f)
for scan.Scan() {
2021-09-20 01:23:18 +00:00
if !s.stage1(scan.Text()) {
continue
}
go s.LoadSingleProxy(scan.Text())
count++
}
if err := f.Close(); err != nil {
s.dbgPrint(err.Error())
2021-09-20 01:23:18 +00:00
return count
}
2021-09-20 01:23:18 +00:00
return count
}
// LoadSingleProxy loads a SOCKS proxy into our queue as the format: 127.0.0.1:1080 (host:port)
2021-09-20 01:23:18 +00:00
func (s *Swamp) LoadSingleProxy(sock string) {
inChan <- sock
}
// LoadMultiLineString loads a multiine string object with one (host:port) SOCKS proxy per line
2021-09-20 01:23:18 +00:00
func (s *Swamp) LoadMultiLineString(socks string) int {
var count int
scan := bufio.NewScanner(strings.NewReader(socks))
for scan.Scan() {
2021-09-20 01:23:18 +00:00
go s.LoadSingleProxy(scan.Text())
count++
}
if count < 1 {
2021-09-20 01:23:18 +00:00
return 0
}
2021-09-20 01:23:18 +00:00
return count
}
// ClearSOCKSList clears the slice of proxies that we continually draw from at random for validation
// * Other operations (proxies that are still in buffered channels) will resume unless paused.
func (s *Swamp) ClearSOCKSList() {
s.mu.Lock()
defer s.mu.Unlock()
2021-09-20 01:23:18 +00:00
s.swampmap = make(map[string]*Proxy)
}