|
@@ -0,0 +1,52 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ "net/http"
|
|
|
+ "net"
|
|
|
+ "regexp"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func GetOutboundIP() net.IP {
|
|
|
+ conn, err := net.Dial("udp", "8.8.8.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) {
|
|
|
+ fmt.Fprintf(w, "HTTP-статус 200")
|
|
|
+}
|
|
|
+
|
|
|
+func info_students(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Fprintf(w, " Любовникова Екатерина Александровна 791")
|
|
|
+}
|
|
|
+
|
|
|
+func state(w http.ResponseWriter, r *http.Request) {
|
|
|
+ Ip := GetOutboundIP().String()
|
|
|
+ regex := regexp.MustCompile("\\W[0-9]*\\W[0-9]*")
|
|
|
+ Ip2 := regex.ReplaceAllString(Ip, ".*.*")
|
|
|
+ fmt.Fprintf(w, Ip2)
|
|
|
+ fmt.Fprintf(w, " Любовникова Екатерина Александровна ")
|
|
|
+ TheGivenTime := time.Now()
|
|
|
+ fmt.Fprintf(w, TheGivenTime.Format(" 2006-01-02 3:4:5 pm\n"))
|
|
|
+}
|
|
|
+
|
|
|
+func main() {
|
|
|
+ http.HandleFunc("/OK/", status)
|
|
|
+ http.HandleFunc("/Info/", info_students)
|
|
|
+ http.HandleFunc("/Status/", state)
|
|
|
+ err := http.ListenAndServe(":2000", nil)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal("ListenAndServe: ", err)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|