Weitere Tests für IPv6
All checks were successful
release-tag / release-image (push) Successful in 45s
All checks were successful
release-tag / release-image (push) Successful in 45s
This commit is contained in:
58
main.go
58
main.go
@@ -17,6 +17,12 @@ import (
|
|||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
DNS-Status-Code übersicht: https://pkg.go.dev/github.com/miekg/dns@v1.1.62#TypeSOA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
type DB map[string]dns_entry
|
type DB map[string]dns_entry
|
||||||
|
|
||||||
var D map[string]dns_entry
|
var D map[string]dns_entry
|
||||||
@@ -213,6 +219,57 @@ func handlerIP(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte(remoteIP))
|
w.Write([]byte(remoteIP))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handlerIPv6Pro(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Funktion zum Extrahieren der IP-Adresse
|
||||||
|
getIP := func(r *http.Request) string {
|
||||||
|
// Prüfen, ob X-Forwarded-For vorhanden ist (für Proxys)
|
||||||
|
xff := r.Header.Get("X-Forwarded-For")
|
||||||
|
if xff != "" {
|
||||||
|
// X-Forwarded-For kann mehrere IPs enthalten (Client, Proxy, etc.)
|
||||||
|
ips := strings.Split(xff, ",")
|
||||||
|
return strings.TrimSpace(ips[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüfen, ob X-Real-IP vorhanden ist (eine alternative Proxy-Header-Option)
|
||||||
|
xRealIP := r.Header.Get("X-Real-IP")
|
||||||
|
if xRealIP != "" {
|
||||||
|
return xRealIP
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: RemoteAddr verwenden
|
||||||
|
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
|
if err != nil {
|
||||||
|
return r.RemoteAddr // Falls SplitHostPort fehlschlägt, gib die Raw-Adresse zurück
|
||||||
|
}
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
|
||||||
|
// Die IP-Adresse des Clients auslesen
|
||||||
|
clientIP := getIP(r)
|
||||||
|
|
||||||
|
// Prüfen, ob IPv4 oder IPv6
|
||||||
|
parsedIP := net.ParseIP(clientIP)
|
||||||
|
if parsedIP == nil {
|
||||||
|
http.Error(w, "Ungültige IP-Adresse", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ausgabe der Adresse
|
||||||
|
if parsedIP.To4() != nil {
|
||||||
|
fmt.Fprintf(w, "Client IPv4-Adresse: %s\n", clientIP)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "Client IPv6-Adresse: %s\n", clientIP)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optionale Ausgabe aller Header (Debugging)
|
||||||
|
fmt.Fprintln(w, "\nAlle HTTP-Header:")
|
||||||
|
for name, values := range r.Header {
|
||||||
|
for _, value := range values {
|
||||||
|
fmt.Fprintf(w, "%s: %s\n", name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
|
func handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
// Bereite die Antwort vor
|
// Bereite die Antwort vor
|
||||||
msg := new(dns.Msg)
|
msg := new(dns.Msg)
|
||||||
@@ -415,6 +472,7 @@ func main() {
|
|||||||
|
|
||||||
http.HandleFunc("/", handler)
|
http.HandleFunc("/", handler)
|
||||||
http.HandleFunc("/ip", handlerIP)
|
http.HandleFunc("/ip", handlerIP)
|
||||||
|
http.HandleFunc("/ipv6", handlerIPv6Pro)
|
||||||
|
|
||||||
/* DNS-PART */
|
/* DNS-PART */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user