main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "fmt"
  4. "io"
  5. "net/http"
  6. "regexp"
  7. "time"
  8. )
  9. func main() {
  10. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  11. http.ServeFile(w, r, "0.0")
  12. })
  13. http.HandleFunc("/int", func(w http.ResponseWriter, r *http.Request) {
  14. ip := r.FormValue("ip address")
  15. mask := r.FormValue("mask")
  16. gateway := r.FormValue("gateway")
  17. dns := r.FormValue("DNS")
  18. fmt.Fprintf(w, " ip address: 90.111.188.111 %s\n mask: 255.255.255.0 %s\n gateway: 90.111.188.111 %s\n DNS: 8.8.8.8 %s\n", ip, mask, gateway, dns)
  19. })
  20. http.ListenAndServe(":8080", nil)
  21. }
  22. var re = regexp.MustCompile("(\\d+\\.)(\\d+\\.\\d+)(\\.\\d+)")
  23. func sayinfo(w http.ResponseWriter, r *http.Request) {
  24. fmt.Fprintf(w, "Сизов Валентин 794")
  25. }
  26. func status(w http.ResponseWriter, r *http.Request) {
  27. fmt.Fprintf(w, "794svs\n")
  28. response, error := http.Get("https://api.ipify.org/?format=text")
  29. if error != nil {
  30. fmt.Println(error)
  31. }
  32. body, error := io.ReadAll(response.Body)
  33. if error != nil {
  34. fmt.Println(error)
  35. }
  36. response.Body.Close()
  37. out := re.ReplaceAllString(string(body), "$1***.***$3")
  38. fmt.Fprint(w, "IP-address: ", out, "\n")
  39. now := time.Now()
  40. fmt.Fprintf(w, now.Format("2022-12-10 3:4:5 pm"))
  41. }