Skip to content

Commit

Permalink
优化 2022-06-16 10:02:1655344931
Browse files Browse the repository at this point in the history
  • Loading branch information
x51pwn committed Jun 16, 2022
1 parent 8800433 commit 1ad1124
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ func ACME(g *gin.Context) {
g.JSON(http.StatusOK, "ok")
}
}

func getip(g *gin.Context) {
ip, ok := g.Request.Header["X-Real-IP"]
host, ok1 := g.Request.Header["Host"]
if ok && ok1 && 0 < len(host) && 0 < len(ip) && strings.HasPrefix(host[0], "ip.") {
g.JSON(http.StatusOK, ip[0])
return
}
g.JSON(http.StatusBadRequest, "can not get ip")
//return false
}
func ip2domain(g *gin.Context) {
if nil == dbs {
logrus.Debug("dbs is nil")
Expand Down Expand Up @@ -357,6 +368,7 @@ func HttpApiServer() {
router.POST(s1, ACME)
s1 = "/ip2domain"
router.GET(s1, ip2domain)
router.GET("/", getip)
router.POST(s1, ip2domain)
router.GET("/dnslog", dnsRes)
router.Run(httpHost)
Expand Down
2 changes: 1 addition & 1 deletion test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func getDate() string {
}
func main() {
log.Println(getDate())
xx0 := db1.GetDb(&Ips{}, "/Users/51pwn/MyWork/DNS_Server/db/mydbfile")
xx0 := db1.GetDb(&Ips{}, "db/mydbfile")
xx0.AutoMigrate(&Ips{}, &Result{})
db1.GetTableName(&Result{})
var r Result = Result{Ips: []Ips{Ips{Ip: "11.2.33.4"}}, Dns: "xxx.com", Date: getDate()}
Expand Down
6 changes: 2 additions & 4 deletions up4me1.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
rm -rf release
rm -rf DNS_Server_linux DNS_Server
go mod vendor
go mod verify
gobuild . DNS_Server
scp -i ~/.ssh/id_rsa -C -r -P $newSshPort DNS_Server_linux root@${newIp}:/root/tools/DNS_Server_linux_amd64
rm -rf DNS_Server_linux
rm -rf DNS_Server
scp -i ~/.ssh/id_rsa -C -r -P $newSshPort release/DNS_Server_linux root@${newIp}:/root/tools/DNS_Server_linux_amd64
rm -rf release

0 comments on commit 1ad1124

Please sign in to comment.