rewrite in go and add support for ipv6

This commit is contained in:
mxmlndml
2024-03-22 13:08:43 +01:00
parent 352e9e1874
commit cad4064f3e
18 changed files with 381 additions and 854 deletions

24
public_ip.go Normal file
View File

@@ -0,0 +1,24 @@
package main
import (
"fmt"
"io"
"log"
"net/http"
"strings"
)
func GetPublicIP(version int8) string {
url := fmt.Sprintf("https://ipv%d.icanhazip.com", version)
resp, err := http.Get(url)
if err != nil {
log.Panic("Failed to get public IP: ", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
return strings.TrimSpace(string(body))
}