01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
class
NtMacAddress {
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
function
getMac(
$what
) {
31.
$what
= &
strtolower
(
$what
);
32.
if
(
$what
==
'server'
) {
33.
return
$this
->__server_macaddress();
34.
}
35.
elseif
(
$what
==
'client'
) {
36.
return
$this
->__client_macaddress();
37.
}
38.
else
{
39.
return
'\'client\' or \'server\' ?'
;
40.
}
41.
}
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
function
__server_macaddress() {
52.
$output
= Array();
53.
exec
(
'netstat -r'
,
$output
);
54.
for
(
$a
= 0,
$b
= &
count
(
$output
);
$a
<
$b
;
$a
++ ) {
55.
if
( preg_match(
"/(?i)([a-z0-9]{2} ){6}/"
,
$output
[
$a
] ) == true ) {
56.
$macaddress
= &
$output
[
$a
];
57.
$uniquekey
= &md5(
$macaddress
);
58.
$output
[
$a
] = &preg_replace(
"/(?i)([^a-z0-9]*?)([a-z0-9]{2} ){6}/i"
,
"\\1 {$uniquekey} "
,
$output
[
$a
] );
59.
$output
[
$a
] = &
explode
(
" {$uniquekey} "
,
$output
[
$a
] );
60.
$uniquekey
= Array( trim(
$output
[
$a
][0] ), trim(
$output
[
$a
][1] ) );
61.
$macaddress
= &
str_replace
(
$uniquekey
,
""
,
$macaddress
);
62.
return
trim(
$macaddress
);
63.
}
64.
}
65.
return
'not found'
;
66.
}
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
function
__client_macaddress() {
77.
$output
= Array();
78.
exec
(
'nbtstat -A '
.
$_SERVER
[
'REMOTE_ADDR'
],
$output
);
79.
$reg
=
'([a-f0-9]{2}\-){5}([a-f0-9]{2})'
;
80.
for
(
$a
= 0,
$b
= &
count
(
$output
);
$a
<
$b
;
$a
++ ) {
81.
if
( preg_match(
"/(?i){$reg}/"
,
$output
[
$a
] ) == true ) {
82.
return
preg_replace(
"/(?iU)(.+)({$reg})(.*)/"
,
"\\2"
,
$output
[
$a
] );
83.
}
84.
}
85.
return
'not found'
;
86.
}
87.
}