/** * @Author: jager * @Email: lhj168os@gmail.com * @File: network * @Date: 2022/2/7 5:35 下午 * @package: network * @Version: v1.0.0 * * @Description: * */ package network import ( "github.com/gin-gonic/gin" "github.com/jageros/hawox/errcode" "github.com/jageros/hawox/httpx" "idata/internal/apity" "idata/internal/service/user" "net" "net/http" ) func MyIp(ctx *gin.Context) { if !user.Auth(ctx, apity.SelfIp) { return } addr := ctx.ClientIP() ctx.String(http.StatusOK, addr) } func Domain2IP(ctx *gin.Context) { if !user.Auth(ctx, apity.DomainIP) { return } domain, ok := httpx.DecodeUrlVal(ctx, "domain") if !ok { return } addrs, err := net.LookupHost(domain) if err != nil { httpx.ErrInterrupt(ctx, errcode.WithErrcode(1, err)) return } httpx.PkgMsgWrite(ctx, map[string]interface{}{"addrs": addrs}) } func IP2Domain(ctx *gin.Context) { if !user.Auth(ctx, apity.IPDomain) { return } ip, ok := httpx.DecodeUrlVal(ctx, "ip") if !ok { return } names, err := net.LookupAddr(ip) if err != nil { httpx.ErrInterrupt(ctx, errcode.WithErrcode(1, err)) return } httpx.PkgMsgWrite(ctx, map[string]interface{}{"names": names}) }