MCPcopy
hub / github.com/EverythingSuckz/TG-FileStreamBot / GetPublicIP

Function GetPublicIP

config/config.go:264–278  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

262}
263
264func 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
280func checkIfIpAccessible(ip string) bool {
281 conn, err := net.Dial("tcp", ip+":80")

Callers 1

getIPFunction · 0.85

Calls 3

checkIfIpAccessibleFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected