Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package cli
  2. import (
  3. "context"
  4. "io"
  5. "net"
  6. "net/http"
  7. "strings"
  8. "github.com/9seconds/mtg/v2/essentials"
  9. "github.com/9seconds/mtg/v2/mtglib"
  10. )
  11. func getIP(ntw mtglib.Network, protocol string) net.IP {
  12. dialer := ntw.NativeDialer()
  13. client := ntw.MakeHTTPClient(func(ctx context.Context, network, address string) (essentials.Conn, error) {
  14. conn, err := dialer.DialContext(ctx, protocol, address)
  15. if err != nil {
  16. return nil, err
  17. }
  18. return essentials.WrapNetConn(conn), err
  19. })
  20. req, err := http.NewRequest(http.MethodGet, "https://ifconfig.co", nil) //nolint: noctx
  21. if err != nil {
  22. panic(err)
  23. }
  24. req.Header.Add("Accept", "text/plain")
  25. resp, err := client.Do(req)
  26. if err != nil {
  27. return nil
  28. }
  29. if resp.StatusCode != http.StatusOK {
  30. return nil
  31. }
  32. defer func() {
  33. io.Copy(io.Discard, resp.Body) //nolint: errcheck
  34. resp.Body.Close() //nolint: errcheck
  35. }()
  36. data, err := io.ReadAll(resp.Body)
  37. if err != nil {
  38. return nil
  39. }
  40. return net.ParseIP(strings.TrimSpace(string(data)))
  41. }