|
@@ -1,39 +0,0 @@
|
|
-package main
|
|
|
|
-
|
|
|
|
-import (
|
|
|
|
- "fmt"
|
|
|
|
- "io"
|
|
|
|
- "net/http"
|
|
|
|
- "regexp"
|
|
|
|
- "time"
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-func main() {
|
|
|
|
- http.HandleFunc("/status", status)
|
|
|
|
- http.ListenAndServe(":8080", nil)
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-var re = regexp.MustCompile("(\\d+\\.)(\\d+\\.\\d+)(\\.\\d+)")
|
|
|
|
-
|
|
|
|
-func status(w http.ResponseWriter, r *http.Request) {
|
|
|
|
- fmt.Fprintf(w, "PAL\n")
|
|
|
|
- // make GET request
|
|
|
|
- response, error := http.Get("https://api.ipify.org/?format=text")
|
|
|
|
- if error != nil {
|
|
|
|
- fmt.Println(error)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // read response body
|
|
|
|
- body, error := io.ReadAll(response.Body)
|
|
|
|
- if error != nil {
|
|
|
|
- fmt.Println(error)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- response.Body.Close()
|
|
|
|
-
|
|
|
|
- out := re.ReplaceAllString(string(body), "$1***.***$3")
|
|
|
|
- fmt.Fprint(w, "IP-address: ", out, "\n")
|
|
|
|
- now := time.Now()
|
|
|
|
- fmt.Fprintf(w, now.Format("2006-01-02 3:4:5 pm"))
|
|
|
|
-}
|
|
|