2021-09-14 07:28:10 +00:00
|
|
|
package pxndscvm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"os"
|
2021-09-18 08:33:40 +00:00
|
|
|
"strconv"
|
2021-09-14 07:28:10 +00:00
|
|
|
"strings"
|
2021-09-18 10:38:22 +00:00
|
|
|
|
|
|
|
ipa "inet.af/netaddr"
|
2021-09-14 07:28:10 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-09-14 07:28:10 +00:00
|
|
|
// 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))
|
2021-09-14 07:28:10 +00:00
|
|
|
|
|
|
|
f, err := os.Open(seedFile)
|
|
|
|
if err != nil {
|
2021-09-20 01:23:18 +00:00
|
|
|
panic(err)
|
|
|
|
return 0
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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++
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
s.dbgPrint(err.Error())
|
2021-09-20 01:23:18 +00:00
|
|
|
return count
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-20 01:23:18 +00:00
|
|
|
|
|
|
|
return count
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2021-09-14 07:28:10 +00:00
|
|
|
// 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
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2021-09-14 07:28:10 +00:00
|
|
|
// 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 {
|
2021-09-18 08:33:40 +00:00
|
|
|
var count int
|
2021-09-14 07:28:10 +00:00
|
|
|
scan := bufio.NewScanner(strings.NewReader(socks))
|
|
|
|
for scan.Scan() {
|
2021-09-20 01:23:18 +00:00
|
|
|
go s.LoadSingleProxy(scan.Text())
|
|
|
|
count++
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 08:33:40 +00:00
|
|
|
if count < 1 {
|
2021-09-20 01:23:18 +00:00
|
|
|
return 0
|
2021-09-18 08:33:40 +00:00
|
|
|
}
|
2021-09-20 01:23:18 +00:00
|
|
|
return count
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2021-09-14 07:28:10 +00:00
|
|
|
// 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)
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|