2022-05-23 01:05:50 +00:00
|
|
|
package prox5
|
2021-09-14 07:28:10 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2022-09-28 23:44:23 +00:00
|
|
|
"errors"
|
2021-10-25 09:57:38 +00:00
|
|
|
"io"
|
2021-09-14 07:28:10 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
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.
|
2022-07-25 07:14:26 +00:00
|
|
|
// Expects one of the following formats for each line:
|
2022-09-23 01:57:35 +00:00
|
|
|
// - 127.0.0.1:1080
|
|
|
|
// - 127.0.0.1:1080:user:pass
|
|
|
|
// - yeet.com:1080
|
|
|
|
// - yeet.com:1080:user:pass
|
|
|
|
// - [fe80::2ef0:5dff:fe7f:c299]:1080
|
|
|
|
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) LoadProxyTXT(seedFile string) (count int) {
|
2021-10-25 10:32:59 +00:00
|
|
|
f, err := os.Open(seedFile)
|
|
|
|
if err != nil {
|
2022-09-22 23:45:15 +00:00
|
|
|
p5.dbgPrint(simpleString(err.Error()))
|
2021-10-25 10:32:59 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-10-23 17:25:28 +00:00
|
|
|
defer func() {
|
2021-10-25 10:32:59 +00:00
|
|
|
if err := f.Close(); err != nil {
|
2022-09-22 23:45:15 +00:00
|
|
|
p5.dbgPrint(simpleString(err.Error()))
|
2021-10-25 10:32:59 +00:00
|
|
|
}
|
2021-10-23 17:25:28 +00:00
|
|
|
}()
|
2021-09-14 07:28:10 +00:00
|
|
|
|
2021-10-25 10:32:59 +00:00
|
|
|
bs, err := io.ReadAll(f)
|
2021-09-14 07:28:10 +00:00
|
|
|
if err != nil {
|
2022-09-22 23:45:15 +00:00
|
|
|
p5.dbgPrint(simpleString(err.Error()))
|
2021-09-20 01:23:18 +00:00
|
|
|
return 0
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-10-25 09:57:38 +00:00
|
|
|
sockstr := string(bs)
|
2021-09-14 07:28:10 +00:00
|
|
|
|
2022-09-22 23:45:15 +00:00
|
|
|
return p5.LoadMultiLineString(sockstr)
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2022-07-25 07:14:26 +00:00
|
|
|
// LoadSingleProxy loads a SOCKS proxy into our map.
|
|
|
|
// Expects one of the following formats:
|
2022-09-23 01:57:35 +00:00
|
|
|
// - 127.0.0.1:1080
|
|
|
|
// - 127.0.0.1:1080:user:pass
|
|
|
|
// - yeet.com:1080
|
|
|
|
// - yeet.com:1080:user:pass
|
|
|
|
// - [fe80::2ef0:5dff:fe7f:c299]:1080
|
|
|
|
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) LoadSingleProxy(sock string) bool {
|
2022-09-28 23:44:23 +00:00
|
|
|
var ok bool
|
2022-08-29 05:41:34 +00:00
|
|
|
if sock, ok = filter(sock); !ok {
|
2022-09-28 23:44:23 +00:00
|
|
|
return false
|
2021-10-25 04:15:06 +00:00
|
|
|
}
|
2022-09-28 23:44:23 +00:00
|
|
|
if err := p5.loadSingleProxy(sock); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2021-10-25 04:15:06 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) loadSingleProxy(sock string) error {
|
|
|
|
if _, ok := p5.proxyMap.add(sock); !ok {
|
2022-09-28 23:44:23 +00:00
|
|
|
return errors.New("proxy already exists")
|
2021-10-25 10:32:59 +00:00
|
|
|
}
|
2022-09-28 23:44:23 +00:00
|
|
|
return nil
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2022-07-25 07:14:26 +00:00
|
|
|
// LoadMultiLineString loads a multiine string object with proxy per line.
|
|
|
|
// Expects one of the following formats for each line:
|
2022-09-23 01:57:35 +00:00
|
|
|
// - 127.0.0.1:1080
|
|
|
|
// - 127.0.0.1:1080:user:pass
|
|
|
|
// - yeet.com:1080
|
|
|
|
// - yeet.com:1080:user:pass
|
|
|
|
// - [fe80::2ef0:5dff:fe7f:c299]:1080
|
|
|
|
// - [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) 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() {
|
2022-09-23 22:57:46 +00:00
|
|
|
if err := p5.loadSingleProxy(scan.Text()); err != nil {
|
|
|
|
continue
|
2021-10-25 09:57:38 +00:00
|
|
|
}
|
2022-09-23 22:57:46 +00:00
|
|
|
count++
|
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-21 12:24:30 +00:00
|
|
|
// ClearSOCKSList clears the map of proxies that we have on record.
|
2021-10-23 14:26:23 +00:00
|
|
|
// Other operations (proxies that are still in buffered channels) will continue.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) ClearSOCKSList() {
|
|
|
|
p5.proxyMap.clear()
|
2021-09-14 07:28:10 +00:00
|
|
|
}
|