时间:2021-07-01 10:21:17 帮助过:26人阅读
如果使用php命令行里想获取etho网卡的IP怎么处理呢 ?
public function get_server_ip() { if (PHP_SAPI === 'cli'){ $buffer = ""; $handle = popen("ifconfig eth0|grep 'inet addr'|awk -F'[ :]' '{print $13}'", 'r'); while(!feof($handle)) { $buffer.=fgets($handle); } pclose($handle); $server_ip = rtrim($buffer); }else{ if (isset($_SERVER)) { if($_SERVER['SERVER_ADDR']) { $server_ip = $_SERVER['SERVER_ADDR']; } else { $server_ip = $_SERVER['LOCAL_ADDR']; } } else { $server_ip = getenv('SERVER_ADDR'); } } return $server_ip; }
以上就是php获取linux命令结果的实例代码的详细内容,更多请关注Gxl网其它相关文章!