feat: project init
This commit is contained in:
parent
3ef2214054
commit
4cc618c2ab
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/kenaito-dns.iml" filepath="$PROJECT_DIR$/.idea/kenaito-dns.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
24
README.md
24
README.md
|
@ -1,3 +1,25 @@
|
|||
# kenaito-dns
|
||||
|
||||
DNS服务器,可通过WEB管理界面随意设置灵活的解析规则。为了纯血自研devops平台而生。
|
||||
DNS服务器,可通过Web管理界面随意设置灵活的解析规则。为了纯血自研devops平台而生。
|
||||
|
||||
# Go代理地址配置
|
||||
|
||||
[去看看](https://blog.odboy.cn/go%E5%85%A8%E5%B1%80%E9%85%8D%E7%BD%AE%E5%9B%BD%E5%86%85%E6%BA%90-by-odboy/)
|
||||
|
||||
# nslookup 命令不存在解决
|
||||
|
||||
```shell
|
||||
yum install bind-utils -y
|
||||
```
|
||||
|
||||
# nslookup指定dns服务器查询
|
||||
|
||||
```shell
|
||||
# 这里dns服务器为 192.168.1.103
|
||||
nslookup example.com 192.168.1.103
|
||||
```
|
||||
|
||||
# 本程序所用依赖,感谢开源者的无私奉献
|
||||
|
||||
- [数据库操作](http://xorm.topgoer.com/)
|
||||
- [DNS解析](https://github.com/miekg/dns)
|
|
@ -0,0 +1,13 @@
|
|||
module awesomeProject
|
||||
|
||||
go 1.19
|
||||
|
||||
require github.com/miekg/dns v1.1.62
|
||||
|
||||
require (
|
||||
golang.org/x/mod v0.18.0 // indirect
|
||||
golang.org/x/net v0.27.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/sys v0.22.0 // indirect
|
||||
golang.org/x/tools v0.22.0 // indirect
|
||||
)
|
|
@ -0,0 +1,12 @@
|
|||
github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
|
||||
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
|
||||
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
|
||||
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
|
||||
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
|
|
@ -0,0 +1,80 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/miekg/dns"
|
||||
"net"
|
||||
)
|
||||
|
||||
// 构建 A 记录的函数 IPV4
|
||||
func handleARecord(q dns.Question, msg *dns.Msg) {
|
||||
name := q.Name
|
||||
targetIp := "192.235.111.111"
|
||||
fmt.Printf("请求解析的域名:%s,解析的目标IP地址:%s\n", name, targetIp)
|
||||
ip := net.ParseIP(targetIp)
|
||||
rr := &dns.A{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: name,
|
||||
Rrtype: dns.TypeA,
|
||||
Class: dns.ClassINET,
|
||||
Ttl: 60,
|
||||
},
|
||||
A: ip,
|
||||
}
|
||||
msg.Answer = append(msg.Answer, rr)
|
||||
}
|
||||
|
||||
//// 构建 A 记录的函数 IPV6
|
||||
//func handleAAAARecord(q dns.Question, msg *dns.Msg) {
|
||||
// ip := net.ParseIP("rsdw::8888")
|
||||
// rr := &dns.AAAA{
|
||||
// Hdr: dns.RR_Header{
|
||||
// Name: q.Name,
|
||||
// Rrtype: dns.TypeAAAA,
|
||||
// Class: dns.ClassINET,
|
||||
// Ttl: 60,
|
||||
// },
|
||||
// AAAA: ip,
|
||||
// }
|
||||
// msg.Answer = append(msg.Answer, rr)
|
||||
//}
|
||||
|
||||
//func handleCNAMERecord(q dns.Question, msg *dns.Msg) {
|
||||
// rr := &dns.CNAME{
|
||||
// Hdr: dns.RR_Header{
|
||||
// Name: q.Name,
|
||||
// Rrtype: dns.TypeCNAME,
|
||||
// Class: dns.ClassINET,
|
||||
// Ttl: 60,
|
||||
// },
|
||||
// Target: "example.com.",
|
||||
// }
|
||||
// msg.Answer = append(msg.Answer, rr)
|
||||
//}
|
||||
//
|
||||
//func handleMXRecord(q dns.Question, msg *dns.Msg) {
|
||||
// rr := &dns.MX{
|
||||
// Hdr: dns.RR_Header{
|
||||
// Name: q.Name,
|
||||
// Rrtype: dns.TypeMX,
|
||||
// Class: dns.ClassINET,
|
||||
// Ttl: 60,
|
||||
// },
|
||||
// Preference: 10,
|
||||
// Mx: "mail.example.com.",
|
||||
// }
|
||||
// msg.Answer = append(msg.Answer, rr)
|
||||
//}
|
||||
//
|
||||
//func handleTXTRecord(q dns.Question, msg *dns.Msg) {
|
||||
// rr := &dns.TXT{
|
||||
// Hdr: dns.RR_Header{
|
||||
// Name: q.Name,
|
||||
// Rrtype: dns.TypeTXT,
|
||||
// Class: dns.ClassINET,
|
||||
// Ttl: 60,
|
||||
// },
|
||||
// Txt: []string{"v=spf1 include:_spf.example.com ~all"},
|
||||
// }
|
||||
// msg.Answer = append(msg.Answer, rr)
|
||||
//}
|
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/miekg/dns"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 注册 DNS 请求处理函数
|
||||
dns.HandleFunc(".", handleDNSRequest)
|
||||
// 设置服务器地址和协议
|
||||
server := &dns.Server{Addr: ":53", Net: "udp"}
|
||||
// 开始监听
|
||||
log.Printf("Starting DNS server on %s\n", server.Addr)
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
log.Fatalf("Failed to start server: %s\n", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
|
||||
msg := new(dns.Msg)
|
||||
msg.SetReply(r)
|
||||
// 将 DNS 响应标记为权威应答
|
||||
msg.Authoritative = true
|
||||
// 将 DNS 响应标记为递归可用
|
||||
// msg.RecursionAvailable = true
|
||||
// 遍历请求中的问题部分,生成相应的回答
|
||||
for _, question := range r.Question {
|
||||
switch question.Qtype {
|
||||
case dns.TypeA:
|
||||
handleARecord(question, msg)
|
||||
//case dns.TypeAAAA:
|
||||
// handleAAAARecord(question, msg)
|
||||
//case dns.TypeCNAME:
|
||||
// handleCNAMERecord(question, msg)
|
||||
//case dns.TypeMX:
|
||||
// handleMXRecord(question, msg)
|
||||
//case dns.TypeTXT:
|
||||
// handleTXTRecord(question, msg)
|
||||
}
|
||||
}
|
||||
// 发送响应
|
||||
w.WriteMsg(msg)
|
||||
}
|
Loading…
Reference in New Issue