从网卡中解析ip

    科技2022-07-11  99

    getServerIp(); /** * 获取ip地址 * */ function getServerIp() { $result = shell_exec("ip addr | grep inet "); $resultArray = explode("\n",$result); $serverIpString = $resultArray[2]; $serverIpString = explode("/",$serverIpString)[0]; $serverIp = str_replace(" ","",$serverIpString); $serverIp = str_replace("inet","",$serverIp); return apiJson(1,"success",$serverIp); } /** * 返回json数据 * @param $code * @param $msg * @param array $data */ function apiJson($code,$msg,$data=[]) { header("Content-Type:application/json;charset=utf8"); $returnData=[]; $returnData['code'] = $code; $returnData['msg'] = $msg; if ($data) { $returnData['data'] = $data; } echo json_encode($returnData); }
    Processed: 0.039, SQL: 8