Files
APIPark/frontend/packages/common/src/utils/ip.ts
T
ScarChin 73435497a2 Feature/1.4 (#154)
- Load balancing (can connect to multiple accounts, automatically switch accounts when there is no quota)
- AI call log
- Model rate configuration
2025-01-07 18:47:08 +08:00

22 lines
657 B
TypeScript

export const extractIPFromURL = (url: string | string[]) => {
if (Array.isArray(url)) {
url = url[0] // 获取第一个 URL
}
if (typeof url !== 'string' || !url.includes('://')) {
console.warn('Invalid URL format')
return null
}
const match = url.match(/https?:\/\/([\d.]+):\d+/)
return match ? match[1] : null
}
export const isPrivateIP = (ip: string) => {
if (typeof ip !== 'string') {
console.error('Invalid IP format')
return false
}
const privateIpRegex =
/^(10\.\d{1,3}\.\d{1,3}\.\d{1,3})$|^(172\.(1[6-9]|2[0-9]|3[0-1])\.\d{1,3}\.\d{1,3})$|^(192\.168\.\d{1,3}\.\d{1,3})$/
return privateIpRegex.test(ip)
}