prox5/list_management.go

90 lines
1.9 KiB
Go
Raw Normal View History

2021-10-09 17:23:13 +00:00
package Prox5
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
ipa "inet.af/netaddr"
)
2021-09-20 01:23:18 +00:00
// throw shit proxies here, get map
2021-09-21 12:24:30 +00:00
// see daemons.go
2021-09-20 01:23:18 +00:00
var inChan chan string
func init() {
2021-09-23 10:07:23 +00:00
inChan = make(chan string, 1000000)
2021-09-20 01:23:18 +00:00
}
func (s *Swamp) stage1(in string) (string, bool) {
2021-09-20 01:23:18 +00:00
if !strings.Contains(in, ":") {
return in, false
2021-09-20 01:23:18 +00:00
}
split := strings.Split(in, ":")
if _, err := ipa.ParseIP(split[0]); err != nil {
return in, false
2021-09-20 01:23:18 +00:00
}
if _, err := strconv.Atoi(split[1]); err != nil {
return in, false
2021-09-20 01:23:18 +00:00
}
return fmt.Sprintf("%s:%s", split[0], split[1]), true
2021-09-20 01:23:18 +00:00
}
2021-09-21 12:24:30 +00:00
// LoadProxyTXT loads proxies from a given seed file and feeds them to the mapBuilder to be later queued automatically for validation.
2021-09-20 01:23:18 +00:00
func (s *Swamp) LoadProxyTXT(seedFile string) int {
var count int
var filtered string
var ok bool
2021-09-21 12:24:30 +00:00
s.dbgPrint("LoadProxyTXT start: " + seedFile)
2021-09-20 01:23:18 +00:00
defer s.dbgPrint("LoadProxyTXT finished: " + strconv.Itoa(count))
f, err := os.Open(seedFile)
if err != nil {
2021-09-20 01:23:18 +00:00
return 0
}
scan := bufio.NewScanner(f)
for scan.Scan() {
if filtered, ok = s.stage1(scan.Text()); !ok {
2021-09-20 01:23:18 +00:00
continue
}
go s.LoadSingleProxy(filtered)
2021-09-20 01:23:18 +00:00
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
}
2021-09-21 12:24:30 +00:00
// LoadSingleProxy loads a SOCKS proxy into our map. Uses 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-21 12:24:30 +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 {
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
}
2021-09-21 12:24:30 +00:00
// ClearSOCKSList clears the map of proxies that we have on record.
// Other operations (proxies that are still in buffered channels) will continue unless paused.
func (s *Swamp) ClearSOCKSList() {
s.swampmap.clear()
}