使用php运行ipconfig命令 [英] Run ipconfig command with php

查看:2286
本文介绍了使用php运行ipconfig命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码来了解访问者(客户)的一些信息。它已经在Xampp上的我的虚拟服务器上运行,但我不能在我的主服务器(主机)上运行。我看到一个空白页。

I use this code to understand some information of visitors (clients). It has been running on my virtual server on Xampp, but I can`t run on my main server (host). I see just a blank page.

$info = system('ipconfig /all');
echo $info;


推荐答案

这可能有助于

服务器IP

您可以从 $ _ SERVER [ SERVER_ADDR']

客户端IP地址

您可以从 $ _ SERVER ['REMOTE_ADDR']

编辑:您在评论中提出如何获取外部命令的输出 - 一种方式是使用反引号,例如

Edit: you ask in comments how to get the output of an external command - one way is to use backticks, e.g.

$ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;

#run the external command, break output into lines
$arp=`arp -a $ipAddress`;
$lines=explode("\n", $arp);

#look for the output line describing our IP address
foreach($lines as $line)
{
   $cols=preg_split('/\s+/', trim($line));
   if ($cols[0]==$ipAddress)
   {
       $macAddr=$cols[1];
   }
}

但是如果客户端不是在局域网上?

好吧,你运气不好,除非你可以让客户端志愿提供这些信息并通过其他方式传输。请参阅Peter G Mac关于使用Javascript的建议。

Well, you're out of luck unless you can have the client volunteer that information and transmit via other means. See Peter G Mac's suggestion for using Javascript.

您也可以尝试以下命令:

you can also try following command

 <?php
  // http://www.php.net/manual/en/function.exec.php#85930

  $_ = null;

  // If you care about the return value, use this:
    passthru("C:\\WINDOWS\\system32\\cmd.exe /c custom.bat",$_);
    header('Content-Type: text/plain');
    echo $_;
  // if you don't care, just use this:
    $_ = exec("C:\\WINDOWS\\system32\\cmd.exe /c custom.bat");
?>

这篇关于使用php运行ipconfig命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆