以下是一个简单的PHP实例,展示如何创建和管理一个IP池:
```php

// 创建一个IP池类
class IP Pool {
private $ips = [];
// 添加IP地址到IP池
public function addIP($ip) {
$this->ips[] = $ip;
}
// 获取IP池中的所有IP地址
public function getAllIPs() {
return $this->ips;
}
// 从IP池中随机选择一个IP地址
public function getRandomIP() {
if (count($this->ips) > 0) {
return $this->ips[array_rand($this->ips)];
} else {
return null;
}
}
}
// 创建IP池实例
$ipPool = new IP Pool();
// 向IP池中添加IP地址
$ipPool->addIP('192.168.1.1');
$ipPool->addIP('192.168.1.2');
$ipPool->addIP('192.168.1.3');
$ipPool->addIP('192.168.1.4');
// 获取所有IP地址
$allIPs = $ipPool->getAllIPs();
echo "









