Add: GetAllSocks ip:port
This commit is contained in:
parent
b16d7e65f7
commit
7d12c724d5
49
actions.go
49
actions.go
@ -1,6 +1,8 @@
|
||||
package proxygonanza
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -9,8 +11,15 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// NewApiClient instantiates a proxybonanza.com API client with the given key using golang's default http client.
|
||||
func NewApiClient(key string) *APIClient {
|
||||
|
||||
func (api *APIClient) debugPrintf(format string, obj ...interface{}) {
|
||||
if api.Debug {
|
||||
fmt.Println(fmt.Sprintf(format, obj...))
|
||||
}
|
||||
}
|
||||
|
||||
// NewAPIClient instantiates a proxybonanza.com API client with the given key using golang's default http client.
|
||||
func NewAPIClient(key string) *APIClient {
|
||||
return &APIClient{
|
||||
Key: key,
|
||||
KnownPackages: make(map[int]PackageDetails),
|
||||
@ -27,7 +36,43 @@ func NewCustomClient(key string, client *http.Client) *APIClient {
|
||||
}
|
||||
}
|
||||
|
||||
// GetAllSOCKSIPsAndPorts will return a slice of IP:Port formatted proxy strings
|
||||
func (api *APIClient) GetAllSOCKSIPsAndPorts() ([]string, error) {
|
||||
packs, err := api.GetProxyPackages()
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
var results []string
|
||||
for _, pack := range packs {
|
||||
packsocks, err := api.GetPackageSOCKS(pack.ID)
|
||||
if err != nil {
|
||||
return results, err
|
||||
}
|
||||
results = append(results, packsocks...)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// fun fact, this wasn't in their api docs.
|
||||
// proxybonanza.com/api/v1/userpackages_ippacks.csv?_delimiter=%3A&userpackage_id=xxxxx&_csvNoHeader=0&_csvFields=ip%2Cport_socks
|
||||
|
||||
// GetPackageSOCKS returns a specified packages SOCKS5 proxies in host:port format.
|
||||
func (api *APIClient) GetPackageSOCKS(packageid int) ([]string, error) {
|
||||
body, err := api.getReq("userpackages_ippacks.csv?_delimiter=%3A&userpackage_id=" + strconv.Itoa(packageid) + "&_csvNoHeader=0&_csvFields=ip%2Cport_socks")
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
var results []string
|
||||
scanner := bufio.NewScanner(bytes.NewReader(body))
|
||||
for i := 0; scanner.Scan(); i++ {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
results = append(results, scanner.Text())
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// GetProxyPackages gets current proxy packages from your account.
|
||||
func (api *APIClient) GetProxyPackages() ([]UserPackage, error) {
|
||||
|
5
api.go
5
api.go
@ -23,11 +23,10 @@ type Package struct {
|
||||
type APIClient struct {
|
||||
Key string
|
||||
KnownPackages map[int]PackageDetails
|
||||
|
||||
c *http.Client
|
||||
Debug bool
|
||||
c *http.Client
|
||||
}
|
||||
|
||||
|
||||
// PackageResponse represents an API response from proxybonanza.com containing proxy package information.
|
||||
type PackageResponse struct {
|
||||
Success bool `json:"success"`
|
||||
|
@ -3,13 +3,17 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.tcp.direct/kayos/proxygonanza"
|
||||
"git.tcp.direct/kayos/proxygonanza/example"
|
||||
)
|
||||
|
||||
func init() {
|
||||
example.ParseArgs()
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := proxygonanza.NewApiClient(os.Args[1])
|
||||
c := proxygonanza.NewAPIClient(example.APIKey)
|
||||
println("getting proxy packages...")
|
||||
|
||||
packs, err := c.GetProxyPackages()
|
28
example/cmd/getsocks/main.go
Normal file
28
example/cmd/getsocks/main.go
Normal file
@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.tcp.direct/kayos/proxygonanza"
|
||||
"git.tcp.direct/kayos/proxygonanza/example"
|
||||
)
|
||||
|
||||
func init() {
|
||||
example.ParseArgs()
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := proxygonanza.NewAPIClient(example.APIKey)
|
||||
if example.Debug {
|
||||
c.Debug = true
|
||||
println("debug enabled")
|
||||
}
|
||||
socks, err := c.GetAllSOCKSIPsAndPorts()
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, line := range socks {
|
||||
println(line)
|
||||
}
|
||||
}
|
@ -2,16 +2,20 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"git.tcp.direct/kayos/proxygonanza"
|
||||
"git.tcp.direct/kayos/proxygonanza/example"
|
||||
)
|
||||
|
||||
func init() {
|
||||
example.ParseArgs()
|
||||
}
|
||||
|
||||
func main() {
|
||||
println("clearing all auth IPs...")
|
||||
|
||||
c := proxygonanza.NewApiClient(os.Args[1])
|
||||
c := proxygonanza.NewAPIClient(example.APIKey)
|
||||
deleted, err := c.DeleteAllAuthIPs()
|
||||
if err != nil {
|
||||
println(err.Error())
|
28
example/common.go
Normal file
28
example/common.go
Normal file
@ -0,0 +1,28 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
Debug = false
|
||||
APIKey string
|
||||
)
|
||||
|
||||
func ParseArgs() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Printf("\t ~*~ ProxyGonanza ~*~ \nhttps://git.tcp.direct/kayos/proxygonanza\n\nFatal: missing API Key \n\nUsage: %s [--verbose|-v] '<apikey>'\n\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, arg := range os.Args {
|
||||
switch arg {
|
||||
case "-d", "--debug", "-v", "--verbose":
|
||||
Debug = true
|
||||
break
|
||||
default:
|
||||
APIKey = arg
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,9 +11,13 @@ import (
|
||||
|
||||
func (api *APIClient) newRequest(method, u string) (r *http.Request) {
|
||||
r, _ = http.NewRequest(method, u, nil)
|
||||
r.Header.Add("accept", "application/json")
|
||||
if !strings.Contains(u, ".csv") {
|
||||
r.Header.Add("accept", "application/json")
|
||||
}
|
||||
r.Header.Add("Authorization", api.Key)
|
||||
|
||||
api.debugPrintf("[%s] %s (Headers: %v)", method, u, r.Header)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user