|
@@ -0,0 +1,37 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "fmt"
|
|
|
|
+ "log"
|
|
|
|
+ "net"
|
|
|
|
+ "net/http"
|
|
|
|
+ "regexp"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func GetOutboundIP() net.IP {
|
|
|
|
+ conn, err := net.Dial("udp", "8.0.0.8:80")
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ defer conn.Close()
|
|
|
|
+ localAddr := conn.LocalAddr().(*net.UDPAddr)
|
|
|
|
+ return localAddr.IP
|
|
|
|
+}
|
|
|
|
+func Status(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ ip := GetOutboundIP().String()
|
|
|
|
+ dt := time.Now()
|
|
|
|
+ regex := regexp.MustCompile("\\W[0-9]*\\W[0-9]*")
|
|
|
|
+ out := regex.ReplaceAllString(ip, ".x.x")
|
|
|
|
+ fmt.Fprintln(w, out)
|
|
|
|
+ fmt.Fprintf(w, "Морозов Дмитрий группа 784\n")
|
|
|
|
+ fmt.Fprintln(w, dt.Format("2006-01-02 3:4:5 pm"))
|
|
|
|
+}
|
|
|
|
+func main() {
|
|
|
|
+ http.HandleFunc("/Status", Status)
|
|
|
|
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ fmt.Fprintf(w, "http ok")
|
|
|
|
+ })
|
|
|
|
+ http.ListenAndServe(":8080", nil)
|
|
|
|
+
|
|
|
|
+}
|