ipv6-test-backend/internal/router/routes/ip/isp.go

32 lines
633 B
Go
Raw Normal View History

2024-08-20 13:38:32 +08:00
package ip
import (
"github.com/gin-gonic/gin"
"ipv6-test-node/internal/pkg/protocol"
"ipv6-test-node/internal/pkg/utils"
"net"
"net/http"
)
func ISP(c *gin.Context) {
var req *protocol.ISPRequest
err := c.BindJSON(&req)
if err != nil {
c.AbortWithStatus(http.StatusInternalServerError)
return
}
asn, err := utils.GetASN(utils.ToIP(net.ParseIP(req.Address)))
if err != nil {
2024-08-20 19:52:40 +08:00
c.AbortWithStatus(http.StatusInternalServerError)
2024-08-20 13:38:32 +08:00
return
}
name, err := utils.GetISPName(asn)
if err != nil {
2024-08-20 19:52:40 +08:00
c.AbortWithStatus(http.StatusInternalServerError)
2024-08-20 13:38:32 +08:00
return
}
c.JSON(http.StatusOK, protocol.ISPResponse{ISP: name})
}