Rev 34 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 34 | Rev 36 | ||
---|---|---|---|
Line 1062... | Line 1062... | ||
1062 | $lowtest = gmp_init($lowtest, 16); |
1062 | $lowtest = gmp_init($lowtest, 16); |
1063 | $hightest = gmp_init($hightest, 16); |
1063 | $hightest = gmp_init($hightest, 16); |
1064 | 1064 | ||
1065 | return (gmp_cmp($mactest, $lowtest) >= 0) && (gmp_cmp($mactest, $hightest) <= 0); |
1065 | return (gmp_cmp($mactest, $lowtest) >= 0) && (gmp_cmp($mactest, $hightest) <= 0); |
1066 | } |
1066 | } |
- | 1067 | ||
- | 1068 | /** |
|
- | 1069 | * Gets the current MAC address of the system |
|
- | 1070 | * @return string|false MAC address of the local system |
|
- | 1071 | */ |
|
- | 1072 | function get_mac_address() { |
|
- | 1073 | static $detected_mac = false; |
|
- | 1074 | ||
- | 1075 | if ($detected_mac !== false) { // false NOT null! |
|
- | 1076 | return $detected_mac; |
|
- | 1077 | } |
|
- | 1078 | ||
- | 1079 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
- | 1080 | // Windows |
|
- | 1081 | $cmds = array( |
|
- | 1082 | "ipconfig /all", // faster |
|
- | 1083 | "getmac" |
|
- | 1084 | ); |
|
- | 1085 | foreach ($cmds as $cmd) { |
|
- | 1086 | $out = array(); |
|
- | 1087 | $ec = -1; |
|
- | 1088 | exec($cmd, $out, $ec); |
|
- | 1089 | if ($ec == 0) { |
|
- | 1090 | $out = implode("\n",$out); |
|
- | 1091 | $m = array(); |
|
- | 1092 | if (preg_match("/([0-9a-f]{2}-[0-9a-f]{2}-[0-9a-f]{2}-[0-9a-f]{2}-[0-9a-f]{2}-[0-9a-f]{2})/ismU", $out, $m)) { |
|
- | 1093 | $detected_mac = strtolower($m[1]); |
|
- | 1094 | return $detected_mac; |
|
- | 1095 | } |
|
- | 1096 | } |
|
- | 1097 | } |
|
- | 1098 | } else if (strtoupper(PHP_OS) == 'DARWIN') { |
|
- | 1099 | // Mac OS X |
|
- | 1100 | $cmds = array( |
|
- | 1101 | "networksetup -listallhardwareports 2>/dev/null", |
|
- | 1102 | "netstat -i 2>/dev/null" |
|
- | 1103 | ); |
|
- | 1104 | foreach ($cmds as $cmd) { |
|
- | 1105 | $out = array(); |
|
- | 1106 | $ec = -1; |
|
- | 1107 | exec($cmd, $out, $ec); |
|
- | 1108 | if ($ec == 0) { |
|
- | 1109 | $out = implode("\n",$out); |
|
- | 1110 | $m = array(); |
|
- | 1111 | if (preg_match("/([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})/ismU", $out, $m)) { |
|
- | 1112 | $detected_mac = $m[1]; |
|
- | 1113 | return $detected_mac; |
|
- | 1114 | } |
|
- | 1115 | } |
|
- | 1116 | } |
|
- | 1117 | } else { |
|
- | 1118 | // Linux |
|
- | 1119 | $addresses = @glob('/sys/class/net/'.'*'.'/address'); |
|
- | 1120 | foreach ($addresses as $x) { |
|
- | 1121 | if (!strstr($x,'/lo/')) { |
|
- | 1122 | $detected_mac = trim(file_get_contents($x)); |
|
- | 1123 | if (substr(mac_type($detected_mac),0,6) == 'EUI-48') { |
|
- | 1124 | return $detected_mac; |
|
- | 1125 | } |
|
- | 1126 | } |
|
- | 1127 | } |
|
- | 1128 | $cmds = array( |
|
- | 1129 | "netstat -ie 2>/dev/null", |
|
- | 1130 | "ifconfig 2>/dev/null" // only available for root (because it is in sbin) |
|
- | 1131 | ); |
|
- | 1132 | foreach ($cmds as $cmd) { |
|
- | 1133 | $out = array(); |
|
- | 1134 | $ec = -1; |
|
- | 1135 | exec($cmd, $out, $ec); |
|
- | 1136 | if ($ec == 0) { |
|
- | 1137 | $out = implode("\n",$out); |
|
- | 1138 | $m = array(); |
|
- | 1139 | if (preg_match("/([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})/ismU", $out, $m)) { |
|
- | 1140 | $detected_mac = $m[1]; |
|
- | 1141 | return $detected_mac; |
|
- | 1142 | } |
|
- | 1143 | } |
|
- | 1144 | } |
|
- | 1145 | } |
|
- | 1146 | ||
- | 1147 | return $detected_mac; |
|
- | 1148 | } |