mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-17 08:38:24 +00:00
feat: now able to limit ip range for token now (close #1275)
This commit is contained in:
16
common/network/ip.go
Normal file
16
common/network/ip.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/songquanpeng/one-api/common/logger"
|
||||
"net"
|
||||
)
|
||||
|
||||
func IsIpInSubnet(ctx context.Context, ip string, subnet string) bool {
|
||||
_, ipNet, err := net.ParseCIDR(subnet)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "failed to parse subnet: %s, subnet: %s", err.Error(), subnet)
|
||||
return false
|
||||
}
|
||||
return ipNet.Contains(net.ParseIP(ip))
|
||||
}
|
Reference in New Issue
Block a user