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 713B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package config
  2. import (
  3. "io/ioutil"
  4. "net"
  5. "net/http"
  6. "strings"
  7. "github.com/juju/errors"
  8. )
  9. func getGlobalIPv4() (net.IP, error) {
  10. return fetchIP("https://v4.ifconfig.co/ip")
  11. }
  12. func getGlobalIPv6() (net.IP, error) {
  13. return fetchIP("https://v6.ifconfig.co/ip")
  14. }
  15. func fetchIP(url string) (net.IP, error) {
  16. resp, err := http.Get(url)
  17. if err != nil {
  18. return nil, err
  19. }
  20. defer resp.Body.Close() // nolint: errcheck
  21. respDataBytes, err := ioutil.ReadAll(resp.Body)
  22. if err != nil {
  23. return nil, err
  24. }
  25. respData := strings.TrimSpace(string(respDataBytes))
  26. ip := net.ParseIP(respData)
  27. if ip == nil {
  28. return nil, errors.Errorf("ifconfig.co returns incorrect IP %s", respData)
  29. }
  30. return ip, nil
  31. }