MAC адрес в PHP или JavaScript

Rostislav

Новичок
MAC адрес в PHP или JavaScript

Возможно ли как-то средствами PHP или м узнать МАК адрес сетевой карты пользователя.
 

Rostislav

Новичок
А если я через прокси выхожу или шлюз, как же я узнаю IP компа пользователя?
 

Tor

Новичок
никак
только если ты его спросишь, а он ответит
 

Rostislav

Новичок
т.е. фактически сделать такое для общего пользования нереально?
 

magic

lancer
PHP:
/**
* get_mac_address
*
* Used to get the MAC address of the host server. It works with Linux,
* Darwin (Mac OS X), and Win XP. It may work with others as some other
* os's have similar ifconfigs to Darwin but they haven't been tested
*
* @access private
  * @return string Mac address if found
  * @return string ERROR_OPEN means config can't be found and thus not opened
  * @return string MAC_404 means mac adress doesn't exist in the config file
  * @return string SAFE_MODE means server is in safe mode so config can't be read
**/
function get_mac_address() {
	if(ini_get('safe_mode')) {
	        # returns invalid because server is in safe mode thus not allowing
	        # sbin reads but will still allow it to open. a bit weird that one.
	        return 'SAFE_MODE';
	}
	
	# if anyone has any clues for windows environments
	# or other server types let me know
	$os = strtolower(PHP_OS);
	if(substr($os, 0, 3)=='win') {
		# this windows version works on xp running apache
		# based server. it has not been tested with anything
		# else, however it should work with NT, and 2000 also
		
		# execute the ipconfig
		exec('ipconfig/all', $lines);
		# seperate the lines
		foreach ($lines as $key=>$line) {
			# check for the mac signature in the line
			if(strpos(strtolower($line), 'physical address')) {
				$trimmed_line = trim($line);
				# take of the mac addres and return
				return trim(substr($trimmed_line, strrpos($trimmed_line, " ")));
			}
		}
	} else {
		# switch between the os's
		switch($os) {
			# not sure if the string is correct for FreeBSD
			# not tested
			case 'freebsd' :
			# not sure if the string is correct for NetBSD
			# not tested
			case 'netbsd' :
			# not sure if the string is correct for Solaris
			# not tested
			case 'solaris' :
			# not sure if the string is correct for SunOS
			# not tested
			case 'sunos' :
			# darwin is mac os x
			# tested only on the client os
			case 'darwin' :
				$os_var = 'ether';
				$os_file = '/sbin/ifconfig';
				break;
			# linux variation
			# tested on server
			case 'linux' :
				$os_var = 'HWaddr';
				$os_file = '/sbin/ifconfig';
				break;
			default :
			break;
		}
		
		# open the ipconfig
		$fp = @popen($os_file, "rb");
		if (!$fp) {
			# returns invalid, cannot open ifconfig
			return 'ERROR_OPEN';
		}
		
		# read the config
		$conf = @fread($fp, 4096);
		@pclose($fp);
		
		# get the pos of the os_var to look for
		$pos = strpos($conf, $os_var);
		if($pos) {
			# seperate out the mac address
			$str1 = trim(substr($conf, ($pos+strlen($os_var))));
			return trim(substr($str1, 0, strpos($str1, "\n")));
		}
	}
	# failed to find the mac address
	return 'MAC_404';
}
-~{}~ 28.11.05 15:24:

Запускается на сервере.
 

magic

lancer
Функция выдает MAC адрес на хосте. Может у него пользователи каждый со своим сервером.
 

SiMM

Новичок
[offtopic]
magic, во-первых, сетевушек может быть больше одной, а во-вторых, windows бывает локализованным
PHP:
$mac = array();
foreach ($lines as $key=>$line)
  # check for the mac signature in the line
  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})#',$line,$tmp))
    $mac[] = $tmp[1];
if ($mac) return $mac;
[/offtopic]
PS: правда нафиг серверу может быть нужен MAC-адрес сетевушки сервера - ума не приложу :) Разве что к железу привязываться.
 

Skeff

Новичок
Скрипт для работы в WINDOWS среде для определения mac адресов локальных машин, даже при наличии локального прокси-сервера, запрещающего как либо работу локальных машин друг с другом.
<?
$REMOTE_ADDR_CL = (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '').
(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != 'unknown' ? ' FW: '.$_SERVER['HTTP_X_FORWARDED_FOR'] : '').
(isset($_SERVER['HTTP_CLIENT_IP']) ? ' CLIENT_IP: '.$_SERVER['HTTP_CLIENT_IP'] : '').
(isset($_SERVER['HTTP_VIA']) ? ' VIA: '.$_SERVER['HTTP_VIA'] : '');

if(isset($HTTP_SERVER_VARS)) {
if(isset($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) {
$realip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
}elseif(isset($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])) {
$realip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
}else{
$realip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
}
}else{
if(getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
$realip = getenv( 'HTTP_X_FORWARDED_FOR' );
}elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
$realip = getenv( 'HTTP_CLIENT_IP' );
}else {
$realip = getenv( 'REMOTE_ADDR' );
}
}

$REMOTE_ADDR=$realip;
echo "Предварительный IP: ".$REMOTE_ADDR.'<br>Результат обработки:<br>';
$arp=null;
$arp=array();
exec("ping ".$REMOTE_ADDR." -n 1 -l 1 -f -r 1");
exec("arp -a ".$REMOTE_ADDR,$arp);
$temp=ereg_replace(" +"," ",$arp[3]);
//print_r ($arp); //для проверки массива раскомментируй строку
$temp=explode(" ",$temp);
//print_r ($temp); //для проверки массива раскомментируй строку
print "IP: ".$temp[1]."<br>";
print "MAC: ".$temp[2];
?>
 
Сверху