32 lines
633 B
Go
32 lines
633 B
Go
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 {
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
name, err := utils.GetISPName(asn)
|
|
if err != nil {
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, protocol.ISPResponse{ISP: name})
|
|
}
|