Fixed naming structure.

This commit is contained in:
moony 2023-03-17 05:28:24 -04:00
parent 5192bf1a1c
commit 035eb62124
5 changed files with 321 additions and 0 deletions

View File

@ -0,0 +1,82 @@
package moonproxy
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
"h12.io/socks"
"git.tcp.direct/moony/endless/internal/moonproxy"
)
func GetHttpTransport(Proxy string) *http.Transport {
ProxyUrl, err := url.Parse(Proxy)
if utils.HandleError(err) {
return &http.Transport{}
}
return &http.Transport{
Proxy: http.ProxyURL(ProxyUrl),
}
}
func GetSocksTranport(Proxy string) *http.Transport {
return &http.Transport{
Dial: socks.Dial(fmt.Sprintf("%s?timeout=%ds", Proxy, utils.Config.Filter.Timeout)),
}
}
func GetTransport(Proxy string) *http.Transport {
if strings.Contains(Proxy, "http://") {
return GetHttpTransport(Proxy)
} else {
return GetSocksTranport(Proxy)
}
}
func ProxyReq(req string, proxy string) (res *http.Response, err error) {
ReqUrl, err := url.Parse(req)
if utils.HandleError(err) {
return nil, err
}
client := &http.Client{
Timeout: time.Duration(time.Duration(utils.Config.Filter.Timeout) * time.Second),
Transport: GetTransport(proxy),
}
res, err = client.Get(ReqUrl.String())
return res, err
}
func CheckProxy(Proxy string) {
response, err := ProxyReq("https://api.ipify.org", Proxy)
if err != nil {
if utils.Config.Options.ShowDeadProxies {
utils.Log(fmt.Sprintf("[x] [DEAD] [%s]", Proxy))
}
return
}
defer response.Body.Close()
content, err := io.ReadAll(response.Body)
if utils.HandleError(err) {
return
}
is_elite := string(content) != utils.ActualIp
utils.Log(fmt.Sprintf("[!] [ALIVE] [ELITE: %v] [%s]", is_elite, Proxy))
utils.Valid++
if !is_elite && !utils.Config.Options.SaveTransparent {
return
}
utils.AppendFile("checked.txt", Proxy)
}

View File

@ -0,0 +1,73 @@
package moonproxy
import (
"fmt"
"io"
"net/http"
"strings"
"time"
"github.com/zenthangplus/goccm"
"git.tcp.direct/moony/endless/internal/utils"
)
func ScrapeUrl(Url string, ProxyType string) {
utils.Log(fmt.Sprintf("[+] Scraping [%s] proxies from [%s]", ProxyType, Url))
resp, err := http.Get(Url)
if utils.HandleError(err) {
return
}
defer resp.Body.Close()
if resp.StatusCode == 403 || resp.StatusCode == 404 {
return
}
content, err := io.ReadAll(resp.Body)
if utils.HandleError(err) {
return
}
lines := strings.Split(string(content), "\n")
for _, proxy := range lines {
if proxy == "" {
continue
}
utils.AppendFile("proxies.txt", fmt.Sprintf("%s://%s", ProxyType, proxy))
}
}
func Scrape() {
url_list, err := utils.ReadLines("url,csv")
if utils.HandleError(err) {
return
}
StartTime := time.Now()
c := goccm.New(utils.Config.Options.ScrapeThreads)
for _, url := range url_list {
c.Wait()
s := strings.Split(url, ",")
go func(u string, t string) {
ScrapeUrl(u, t)
c.Done()
}(s[1], s[0])
}
c.WaitAllDone()
utils.Log(
fmt.Sprintf(
"[*] Scraped [%d] urils in [%fs]",
len(url_list),
time.Since(StartTime).Seconds(),
),
)
}

55
internal/utils/config.go Normal file
View File

@ -0,0 +1,55 @@
package utils
import (
"io"
"net/http"
"github.com/BurntSushi/toml"
)
var (
Config = ConfigStruct{}
ActualIp string
Valid = 0
)
type ConfigStruct struct {
Filter struct {
Timeout int `toml:"timeout"`
} `toml:"filter"`
Dev struct {
Debug bool `toml:"debug"`
} `toml:"dev"`
Options struct {
Scrape bool `toml:"scrape"`
Threads int `toml:"threads"`
ScrapeThreads int `toml:"scrape_threads"`
SaveTransparent bool `toml:"save_transparent"`
ShowDeadProxies bool `toml:"show_dead_proxies"`
} `toml:"options"`
}
func GetActualIp() string {
res, err := http.Get("https://api.ipify.org")
if HandleError(err) {
return ""
}
defer res.Body.Close()
content, err := io.ReadAll(res.Body)
if HandleError(err) {
return ""
}
return string(content)
}
func LoadConfig() {
if _, err := toml.DecodeFile("script/config.toml", &Config); err != nil {
panic(err)
}
ActualIp = GetActualIp()
}

47
internal/utils/console.go Normal file
View File

@ -0,0 +1,47 @@
package utils
import (
"fmt"
"strings"
"time"
"github.com/gookit/color"
"github.com/inancgumus/screen"
)
func PrintLogo() {
screen.Clear()
screen.MoveTopLeft()
fmt.Println(`
__ ______
\ \/ / _ \ _ __ _____ ___ _
\ /| |_) | '__/ _ \ \/ / | | |
/ \| __/| | | (_) > <| |_| |
/_/\_\_| |_| \___/_/\_\\__, |
|___/
Coded by Moony - 9d5 until infinity...
`)
}
func Log(Content string) {
date := strings.ReplaceAll(time.Now().Format("15:04:05"), ":", "<fg=353a3b>:</>")
content := fmt.Sprintf("[%s] [%d] %s.", date, Valid, Content)
content = strings.ReplaceAll(content, "DEAD", "<fg=f5291b>DEAD</>")
content = strings.ReplaceAll(content, "ALIVE", "<fg=61eb42>ALIVE</>")
color.Println(content)
}
func HandleError(Err error) bool {
if Err != nil {
if Config.Dev.Debug {
fmt.Println(Err)
}
return true
}
return false
}

64
internal/utils/io.go Normal file
View File

@ -0,0 +1,64 @@
package utils
import (
"bufio"
"fmt"
"os"
"strings"
)
func ReadLines(path string) ([]string, error) {
f, err := os.Open(fmt.Sprintf("data/%s", path))
if err != nil {
return nil, err
}
defer f.Close()
r := bufio.NewReader(f)
bytes := []byte{}
lines := []string{}
for {
line, isPrefix, err := r.ReadLine()
if err != nil {
break
}
bytes = append(bytes, line...)
if !isPrefix {
str := strings.TrimSpace(string(bytes))
if len(str) > 0 {
lines = append(lines, str)
bytes = []byte{}
}
}
}
if len(bytes) > 0 {
lines = append(lines, string(bytes))
}
return lines, nil
}
func AppendFile(FileName string, Content string) {
File, err := os.OpenFile(fmt.Sprintf("data/%s", FileName), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if HandleError(err) {
return
}
_, err = File.WriteString(Content + "\n")
if HandleError(err) {
return
}
File.Close()
}
func RemoveDuplicateStr(strSlice []string) []string {
allKeys := make(map[string]bool)
list := []string{}
for _, item := range strSlice {
if _, value := allKeys[item]; !value {
allKeys[item] = true
list = append(list, item)
}
}
return list
}