web_fuzz.go 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package getter
  2. import (
  3. "io/ioutil"
  4. "log"
  5. "sync"
  6. "github.com/zu1k/proxypool/pkg/proxy"
  7. "github.com/zu1k/proxypool/pkg/tool"
  8. )
  9. func init() {
  10. Register("webfuzz", NewWebFuzzGetter)
  11. }
  12. type WebFuzz struct {
  13. Url string
  14. }
  15. func (w *WebFuzz) Get() proxy.ProxyList {
  16. resp, err := tool.GetHttpClient().Get(w.Url)
  17. if err != nil {
  18. return nil
  19. }
  20. defer resp.Body.Close()
  21. body, err := ioutil.ReadAll(resp.Body)
  22. if err != nil {
  23. return nil
  24. }
  25. return FuzzParseProxyFromString(string(body))
  26. }
  27. func (w *WebFuzz) Get2Chan(pc chan proxy.Proxy, wg *sync.WaitGroup) {
  28. defer wg.Done()
  29. nodes := w.Get()
  30. log.Printf("STATISTIC: WebFuzz\tcount=%d\turl=%s\n", len(nodes), w.Url)
  31. for _, node := range nodes {
  32. pc <- node
  33. }
  34. }
  35. func NewWebFuzzGetter(options tool.Options) (getter Getter, err error) {
  36. urlInterface, found := options["url"]
  37. if found {
  38. url, err := AssertTypeStringNotNull(urlInterface)
  39. if err != nil {
  40. return nil, err
  41. }
  42. return &WebFuzz{Url: url}, nil
  43. }
  44. return nil, ErrorUrlNotFound
  45. }