12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package main
- import (
- "be-vpn/internal/dto"
- "bytes"
- "encoding/json"
- "flag"
- "github.com/tidwall/gjson"
- "io"
- "log"
- "net/http"
- "os"
- "time"
- )
- func main() {
- vip := flag.Bool("vip", false, "vip if or not")
- flag.Parse()
- file, err := os.Open("/home/ubuntu/client.ovpn")
- if err != nil {
- log.Fatalf("can not open file, err: %+v", err)
- }
- buf := bytes.Buffer{}
- if _, err := io.Copy(&buf, file); err != nil {
- log.Fatalf("can not read file, err: %+v", err)
- }
- resp, err := http.Get("https://ipinfo.ipidea.io")
- if err != nil {
- log.Fatalf("can not get resp, err: %+v", err)
- }
- bs, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Fatalf("can not read resp, err: %+v", err)
- }
- countryCode := gjson.Get(string(bs), "country_code").String()
- ip := gjson.Get(string(bs), "ip").String()
- city := gjson.Get(string(bs), "city").String()
- log.Printf("ipinfo: %s", string(bs))
- request := dto.RegisterRequest{Ip: ip, CountryCode: countryCode, CountryName: city, Secret: buf.String(), City: city, Vip: *vip}
- body, err := json.Marshal(request)
- if err != nil {
- log.Printf("err: %+v", err)
- }
- for true {
- // send request
- reader := bytes.NewBuffer(body)
- resp, err := http.Post("http://v.starttransfernow.com/register", "application/json", reader)
- if err != nil {
- log.Printf("err: %+v", err)
- continue
- }
- respBody, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Printf("err: %+v", err)
- }
- log.Printf("resp: %s", string(respBody))
- time.Sleep(3 * time.Second)
- }
- }
|