slave.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "be-vpn/internal/dto"
  4. "bytes"
  5. "encoding/json"
  6. "flag"
  7. "github.com/tidwall/gjson"
  8. "io"
  9. "log"
  10. "net/http"
  11. "os"
  12. "time"
  13. )
  14. func main() {
  15. vip := flag.Bool("vip", false, "vip if or not")
  16. flag.Parse()
  17. file, err := os.Open("/root/client.ovpn")
  18. if err != nil {
  19. log.Fatalf("can not open file, err: %+v", err)
  20. }
  21. buf := bytes.Buffer{}
  22. if _, err := io.Copy(&buf, file); err != nil {
  23. log.Fatalf("can not read file, err: %+v", err)
  24. }
  25. resp, err := http.Get("https://ipinfo.ipidea.io")
  26. if err != nil {
  27. log.Fatalf("can not get resp, err: %+v", err)
  28. }
  29. bs, err := io.ReadAll(resp.Body)
  30. if err != nil {
  31. log.Fatalf("can not read resp, err: %+v", err)
  32. }
  33. countryCode := gjson.Get(string(bs), "country_code").String()
  34. ip := gjson.Get(string(bs), "ip").String()
  35. city := gjson.Get(string(bs), "city").String()
  36. log.Printf("ipinfo: %s", string(bs))
  37. request := dto.RegisterRequest{Ip: ip, CountryCode: countryCode, CountryName: city, Secret: buf.String(), City: city, Vip: *vip}
  38. body, err := json.Marshal(request)
  39. if err != nil {
  40. log.Printf("err: %+v", err)
  41. }
  42. for true {
  43. // send request
  44. reader := bytes.NewBuffer(body)
  45. resp, err := http.Post("http://v.starttransfernow.com/register", "application/json", reader)
  46. if err != nil {
  47. log.Printf("err: %+v", err)
  48. continue
  49. }
  50. respBody, err := io.ReadAll(resp.Body)
  51. if err != nil {
  52. log.Printf("err: %+v", err)
  53. }
  54. log.Printf("resp: %s", string(respBody))
  55. time.Sleep(3 * time.Second)
  56. }
  57. }