12345678910111213141516171819202122232425262728293031323334353637 |
- 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, "niv794\n")
- response, error := http.Get("https://api.ipify.org/?format=text") //API IP-адрес
- if error != nil {
- fmt.Println(error)
- }
- 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")) //дата
- }
|