亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

php語言

如何在php與js中分別獲取客戶度mac地址

時間:2024-09-04 16:23:45 php語言 我要投稿
  • 相關推薦

如何在php與js中分別獲取客戶度mac地址

  導語:如何在php與js中分別獲取客戶度mac地址的呢?學代碼的你懂嗎?下面的是百分網(wǎng)小編為大家搜集的相關資料,供大家參考。

如何在php與js中分別獲取客戶度mac地址

  代碼如下:

  <?php

  class MacAddr

  {

  public $returnArray = array();

  public $macAddr;

  function __contruct($os_type=null){

  if(is_null($os_type)) $os_type = PHP_OS;

  switch (strtolower($os_type)){

  case "linux":

  $this->forLinux();

  break;

  case "solaris":

  break;

  case "unix":

  break;

  case "aix":

  break;

  default:

  $this->forWindows();

  break;

  }

  $temp_array = array();

  foreach($this->returnArray as $value ){

  if(preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i", $value, $temp_array)){

  $this->macAddr = $temp_array[0];

  break;

  }

  }

  unset($temp_array);

  return $this->macAddr;

  }

  function forWindows(){

  @exec("ipconfig /all", $this->returnArray);

  if($this->returnArray)

  return $this->returnArray;

  else{

  $ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";

  if (is_file($ipconfig))

  @exec($ipconfig." /all", $this->returnArray);

  else

  @exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->returnArray);

  return $this->returnArray;

  }

  }

  function forLinux(){

  @exec("ifconfig -a", $this->returnArray);

  return $this->returnArray;

  }

  }

  $mac = new MacAddr(PHP_OS);

  echo $mac->macAddr;

  echo "<br />";

  // 獲取客戶端

  // linux

  $command = "arp -a {$_SERVER['REMOTE_ADDR']}";

  echo $command;

  echo "<br />";

  $result=`{$command}`;

  // windows

  $command = "nbtstat -a {$_SERVER['REMOTE_ADDR']}";

  echo $command;

  echo "<br />";

  $result=`{$command}`;

  print_r($result);

  ?>

  獲取服務端的邏輯沒什么大問題,可能會存在權限問題。

  獲取客戶端的時候,可能會比較慢,arp/nbstat命令執(zhí)行會比較慢。

  復制代碼 代碼如下:

  <script language="JScript" event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for="foo">

  document.forms[0].lbMacAddr.value=unescape(MACAddr);

  </script>

  <script language="JScript" event="OnObjectReady(objObject,objAsyncContext)" for="foo">

  if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true && objObject.MACAddress != null && objObject.MACAddress != "undefined") MACAddr = objObject.MACAddress;

  </script>

  <object id="locator" classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6"></object>

  <object id="foo" classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>

  <script language="JScript">

  var service = locator.ConnectServer();

  var MACAddr ;

  var IPAddr ;

  var DomainAddr;

  var sDNSName;

  service.Security_.ImpersonationLevel=3;

  service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');

  </script>

  <form><input type="text" id='lbMacAddr' name='lbMacAddr' /></form>

  只適用于IE瀏覽器,而且會有告警提示,挺遺憾的。

【如何在php與js中分別獲取客戶度mac地址】相關文章:

php創(chuàng)建cookie獲取方法10-28

PHP實現(xiàn)獲取域名的方法小結(jié)06-08

php如何獲得ip地址09-06

電腦如何自動獲取ip地址06-02

如何實現(xiàn)PHP獲取表單數(shù)據(jù)與HTML嵌入PHP腳本09-23

PHP獲取腳本運行時間的應用10-18

php獲取新浪微博數(shù)據(jù)API的實例代碼08-06

php自定義擴展名獲取函數(shù)示例06-10

PHP獲取遠程文件大小的3種解決方法04-29

PHP中多態(tài)如何實現(xiàn)09-04