ifconfig.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. include '../../../auth.php';
  3. ?>
  4. <?php
  5. //ArOZ Online network hardware detection code written for debian and windows (require exe!)
  6. function remove_utf8_bom($text)
  7. {
  8. $bom = pack('H*','EFBBBF');
  9. $text = preg_replace("/^$bom/", '', $text);
  10. return $text;
  11. }
  12. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  13. exec("getNICinfo.exe");
  14. sleep(1);
  15. $nics = [];
  16. $content = remove_utf8_bom(file_get_contents("NICinfo.txt"));
  17. $data = explode(PHP_EOL,$content);
  18. foreach ($data as $nicinfo){
  19. array_push($nics,explode(",",$nicinfo)[0]);
  20. }
  21. header('Content-Type: application/json');
  22. echo json_encode($nics);
  23. exit();
  24. } else {
  25. $result = [];
  26. exec('sudo ifconfig',$arrayoutput);
  27. foreach ($arrayoutput as $line){
  28. $line = trim($line);
  29. $inlinedoutput .= $line."\n";
  30. }
  31. $InterfaceRawInformation = explode("\n\n",$inlinedoutput);
  32. array_pop($InterfaceRawInformation);
  33. //$prased_data = preg_split("/wlan.|lo|eth./", $unprased_data,-1,PREG_SPLIT_NO_EMPTY);
  34. foreach ($InterfaceRawInformation as $data){
  35. $data = preg_replace('/\n/', '', $data);
  36. preg_match('/(wlan[0-9]+|eth[0-9]+|lo)/', $data, $tmp);
  37. if(isset($tmp[1])){
  38. //$exported_information["InterfaceName"] = $tmp[1];
  39. $exported_information["InterfaceID"] = preg_replace('/\w+([0-9]+)/', '$1', $tmp[1]);
  40. if(strpos($tmp[1], 'eth') !== false){
  41. $exported_information["InterfaceIcon"] = "Ethernet";
  42. }else if(strpos($tmp[1], 'wlan') !== false){
  43. $exported_information["InterfaceIcon"] = "WiFi";
  44. }else if(strpos($tmp[1], 'lo') !== false){
  45. continue;
  46. }else{
  47. $exported_information["InterfaceIcon"] = "Unknown";
  48. }
  49. }else{
  50. $exported_information["InterfaceName"] = "Unknown";
  51. $exported_information["InterfaceIcon"] = "Unknown";
  52. }
  53. preg_match('/HWaddr ([0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z])/', $data, $tmp);
  54. if(isset($tmp[1])){
  55. $exported_information["HardwareAddress"] = $tmp[1];
  56. }else{
  57. preg_match('/ether ([0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z])/', $data, $tmp);
  58. if(isset($tmp[1])){
  59. $exported_information["HardwareAddress"] = $tmp[1];
  60. }else{
  61. $exported_information["HardwareAddress"] = "Unknown";
  62. }
  63. }
  64. preg_match('/inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', $data, $tmp);
  65. if(isset($tmp[1])){
  66. $exported_information["IPv4Address"] = $tmp[1];
  67. }else{
  68. preg_match('/inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', $data, $tmp);
  69. if(isset($tmp[1])){
  70. $exported_information["IPv4Address"] = $tmp[1];
  71. }else{
  72. $exported_information["IPv4Address"] = "Unknown";
  73. }
  74. }
  75. preg_match('/Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', $data, $tmp);
  76. if(isset($tmp[1])){
  77. $exported_information["IPv4SubNetMask"] = $tmp[1];
  78. }else{
  79. preg_match('/mask ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', $data, $tmp);
  80. if(isset($tmp[1])){
  81. $exported_information["IPv4SubNetMask"] = $tmp[1];
  82. }else{
  83. $exported_information["IPv4SubNetMask"] = "Unknown";
  84. }
  85. }
  86. preg_match('/inet6 addr: ([a-zA-Z0-9:]+\/[0-9]+)/', $data, $tmp);
  87. if(isset($tmp[1])){
  88. $exported_information["IPv6Address"] = $tmp[1];
  89. }else{
  90. preg_match('/inet6 ([a-zA-Z0-9:]+)/', $data, $tmp);
  91. if(isset($tmp[1])){
  92. $exported_information["IPv6Address"] = $tmp[1];
  93. }else{
  94. $exported_information["IPv6Address"] = "Unknown";
  95. }
  96. }
  97. array_push($result,$exported_information);
  98. }
  99. header('Content-Type: application/json');
  100. echo json_encode($result);
  101. }
  102. ?>