瀏覽代碼

Загрузить файлы ''

gr794_svs 2 年之前
父節點
當前提交
1d7bafafa2
共有 1 個文件被更改,包括 54 次插入0 次删除
  1. 54 0
      main.go

+ 54 - 0
main.go

@@ -0,0 +1,54 @@
+package main
+
+import (
+	"fmt"
+	"io"
+	"net/http"
+	"regexp"
+	"time"
+)
+
+func main() {
+
+	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+		http.ServeFile(w, r, "0.0")
+	})
+	http.HandleFunc("/int", func(w http.ResponseWriter, r *http.Request) {
+
+		ip := r.FormValue("ip address")
+		mask := r.FormValue("mask")
+		gateway := r.FormValue("gateway")
+		dns := r.FormValue("DNS")
+
+		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)
+	})
+	http.ListenAndServe(":8080", nil)
+
+}
+
+var re = regexp.MustCompile("(\\d+\\.)(\\d+\\.\\d+)(\\.\\d+)")
+
+func sayinfo(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "Сизов Валентин 794")
+
+}
+
+func status(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "794svs\n")
+	response, error := http.Get("https://api.ipify.org/?format=text")
+	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("2022-12-10 3:4:5 pm"))
+}