added logging
This commit is contained in:
parent
6c0ef42e6a
commit
19a63f7715
13
server.go
13
server.go
|
@ -4,11 +4,13 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
ip := GetRealIP(r)
|
||||
fmt.Fprintf(w, ip)
|
||||
WritetoFile(ip)
|
||||
}
|
||||
|
||||
func GetRealIP(r *http.Request) string {
|
||||
|
@ -24,6 +26,17 @@ func GetRealIP(r *http.Request) string {
|
|||
}
|
||||
return IP
|
||||
}
|
||||
func WritetoFile(IP string) {
|
||||
f, err := os.OpenFile("ListofIPs.txt",
|
||||
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.WriteString(IP + "\n"); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
http.HandleFunc("/", handler)
|
||||
log.Fatal(http.ListenAndServe(":8081", nil))
|
||||
|
|
Loading…
Reference in New Issue