<?
//php获取ip的算法
//取得
计算机名、
IP地址与
mac地址等
//by www.jb200.com
if(getenv('HTTP_CLIENT_IP')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR')) {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR')) {
$onlineip = getenv('REMOTE_ADDR');
} else {
$onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
exec ("ping $onlineip");
$macaddress=exec ("arp -a | find /i".' "'.$onlineip.'"');
$computername=exec ('nbtstat -A'.' '.$onlineip.' | find /i "20"');
$MacName=(preg_split("/s+/", trim($macaddress)));
$UserName=(preg_split("/s+/", trim($computername)));
echo "计算机名:".$UserName[0]." --- "."IP 地址:".$MacName[0]." --- "."MAC 地址:".$MacName[1];
?>