primitive log added

This commit is contained in:
MDK
2023-06-30 16:19:52 +08:00
parent 0671552aad
commit 92c900eb01
3 changed files with 10 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"net" "net"
"strconv" "strconv"
@@ -46,6 +47,8 @@ func TtlParser(domain string) uint32 {
func handleReflect(w dns.ResponseWriter, r *dns.Msg) { func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
var ( var (
ip net.IP ip net.IP
port int
id uint16
name string name string
qtype uint16 qtype uint16
) )
@@ -55,9 +58,12 @@ func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
m.Authoritative = true m.Authoritative = true
if addr, ok := w.RemoteAddr().(*net.UDPAddr); ok { if addr, ok := w.RemoteAddr().(*net.UDPAddr); ok {
ip = addr.IP ip = addr.IP
port = addr.Port
} }
id = m.MsgHdr.Id
name = m.Question[0].Name name = m.Question[0].Name
qtype = m.Question[0].Qtype qtype = m.Question[0].Qtype
log.Printf("%v|%v|%v|%v|%v", ip, port, id, name, qtype)
//fmt.Println(ip) //fmt.Println(ip)
//fmt.Println(name) //fmt.Println(name)
//fmt.Println(qtype) //fmt.Println(qtype)
@@ -114,5 +120,6 @@ func main() {
server := &dns.Server{Addr: ":53", Net: "udp"} server := &dns.Server{Addr: ":53", Net: "udp"}
if err := server.ListenAndServe(); err != nil { if err := server.ListenAndServe(); err != nil {
fmt.Println("Failed to set up dns server!") fmt.Println("Failed to set up dns server!")
panic(err)
} }
} }

2
go.mod
View File

@@ -2,7 +2,7 @@ module echodns
go 1.20 go 1.20
require github.com/miekg/dns v1.1.54 require github.com/miekg/dns v1.1.55
require ( require (
golang.org/x/mod v0.7.0 // indirect golang.org/x/mod v0.7.0 // indirect

4
go.sum
View File

@@ -1,5 +1,5 @@
github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI= github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo=
github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY=
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=