()
| 262 | } |
| 263 | |
| 264 | func GetPublicIP() (string, error) { |
| 265 | resp, err := http.Get("https://api.ipify.org?format=text") |
| 266 | if err != nil { |
| 267 | return "", err |
| 268 | } |
| 269 | defer resp.Body.Close() |
| 270 | ip, err := io.ReadAll(resp.Body) |
| 271 | if err != nil { |
| 272 | return "", err |
| 273 | } |
| 274 | if !checkIfIpAccessible(string(ip)) { |
| 275 | return string(ip), errors.New("PORT is blocked by firewall") |
| 276 | } |
| 277 | return string(ip), nil |
| 278 | } |
| 279 | |
| 280 | func checkIfIpAccessible(ip string) bool { |
| 281 | conn, err := net.Dial("tcp", ip+":80") |
no test coverage detected