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
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

global_ips.go 1002B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package config
  2. import (
  3. "context"
  4. "io/ioutil"
  5. "net"
  6. "net/http"
  7. "strings"
  8. "github.com/juju/errors"
  9. )
  10. const ifconfigAddress = "https://ifconfig.co/ip"
  11. func getGlobalIPv4() (net.IP, error) {
  12. return fetchIP("tcp4")
  13. }
  14. func getGlobalIPv6() (net.IP, error) {
  15. return fetchIP("tcp6")
  16. }
  17. func fetchIP(network string) (net.IP, error) {
  18. dialer := &net.Dialer{FallbackDelay: -1}
  19. client := &http.Client{
  20. Jar: nil,
  21. Transport: &http.Transport{
  22. DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
  23. return dialer.DialContext(ctx, network, addr)
  24. },
  25. },
  26. }
  27. resp, err := client.Get(ifconfigAddress)
  28. if err != nil {
  29. return nil, err
  30. }
  31. defer resp.Body.Close() // nolint: errcheck
  32. respDataBytes, err := ioutil.ReadAll(resp.Body)
  33. if err != nil {
  34. return nil, err
  35. }
  36. respData := strings.TrimSpace(string(respDataBytes))
  37. ip := net.ParseIP(respData)
  38. if ip == nil {
  39. return nil, errors.Errorf("ifconfig.co returns incorrect IP %s", respData)
  40. }
  41. return ip, nil
  42. }