Identificare pc univocamente

Altutto

Utente Attivo
30 Set 2013
262
0
16
stubborn.altervista.org
Esiste un modo per identificare in modo univoco e quasi infallibile un computer utilizzando php?
Non andrebbe bene l'identificazione tramite cookies (in quanto potrebbero essere facilmente modificabili dagli utenti) nè tramite IP (che potrebbe essere dinamico).
 

Nefyt

Utente Attivo
17 Apr 2012
1.102
0
0
No non è possibile perché php non puo accedere alle componenti hardware del computer che manda la richiesta
 

flameseeker

Utente Attivo
27 Nov 2013
699
0
0
The client MAC address will not be available to you except in one special circumstance: if the client is on the same ethernet segment as the server.
Non per fare il guastafeste, ma alla fine per riuscire a funzionare nella totalità dei casi..

Well, you're out of luck unless you can have the client volunteer that information and transmit via other means. See Peter G Mac's suggestion for using Javascript
..ci si ritrova a dover trovare escamotage lato client per comunicare i dati di interesse.


Essendo una soluzione facilmente aggirabile non ci pianificherei controlli ben precisi sopra, come quelli per il ban o simili, ma giusto informazioni a scopo statistico (o altro di non particolarmente critico) dal momento che può essere aggirato anche questo controllo.
 

marino51

Utente Attivo
28 Feb 2013
3.204
207
63
Lombardia
vi posto due esempi che ho raccolto e sistemato,
sistemato soprattutto la versione php, che alla prima esecuzione non funzionava
ho tralasciato i controlli di sicurezza, concentrandomi solo sul funzionamento

sarebbe interessante anche per me, raccogliere commenti dalle persone con più esperienza

versione html/javascript

HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Getting MAC Address From Javascript(IE Only)</title>
 
<script language="javascript">
function showMacAddress(){
 
	var obj = new ActiveXObject("WbemScripting.SWbemLocator");
	var s = obj.ConnectServer(".");
	var properties = s.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where MACAddress is not null");
	var e = new Enumerator (properties);

 
	var output;
	output='<table border="0" cellPadding="5px" cellSpacing="1px" bgColor="#CCCCCC">';
	output=output + '<tr bgColor="#EAEAEA"><td>Caption</td><td>MACAddress</td></tr>';
	while(!e.atEnd())

	{
		e.moveNext();
		var p = e.item ();
		if(!p) continue;
		output=output + '<tr bgColor="#FFFFFF">';
		output=output + '<td>' + p.Caption; + '</td>';
		output=output + '<td>' + p.MACAddress + '</td>';
		output=output + '</tr>';
	}

	output=output + '</table>';
	document.getElementById("box").innerHTML=output;
}
</script>
 
</head>
<body>
	<input type="button" value="Show MAC Address" onclick="showMacAddress()" />

	<div id="box">
	</div>
</body>
</html>


versione php

PHP:
<?php 

# http://localhost/test_site/php/test/MacAddress/MacAddress_example.php

require_once("MacAddress.php");

echo $_SERVER["OS"]."<br><br>";

$mac = new MacAddress('0A:1B:2C:3D:4E:5F');
echo $mac->output ('.',4)."<br>";		// 0A1B.2C3D.4E:5F
echo $mac->output ('.',4,'lower')."<br>";	// 0a1b.2c3d.4e5f
echo $mac->output ('-',2,'upper')."<br>";	// 0A-1B-2C-3D-4E-5F
echo $mac->output (':',2,'lower')."<br><br>";	// 0a:1b:2c:3d:4e:5f

$mac2 = new MacAddress ($mac->GetMacAddr());	// mac of ?
echo $mac2->output (':',2,'lower')."<br>";
echo $mac2->output ('.',4,'lower')."<br>";
echo $mac2->output ('.',4,'upper')."<br>";
?>

PHP:
<?php 
/*
 *********************************************************************************************************
 * PHP Class
 * Copyright (c) 2011 Giulio Calzolari <[email protected]> All Rights Reserved. 
 *
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *********************************************************************************************************
 * Original author name cannot be removed.  
 * Authors:	Giulio Calzolari <[email protected]>
 *********************************************************************************************************
 *
 */
class MacAddress
{
  private $mac='';
  
  function __construct($mac)
  {
    $m =  trim($mac) ;
    if (strpos($m,'-')){ $this->mac = str_replace('-','',$m); }
    elseif (strpos($m,'.')){ $this->mac = str_replace('.','',$m); }
    elseif (strpos($m,':')){ $this->mac = str_replace(':','',$m); }
    else { $this->error('No valid MAC ADDRESS : '.$m); }
  }

  function output($sep = ':',$digit = 2, $output = 'normal')  {
    $out = "";
    for ($i=1; $i<strlen($this->mac)+1; $i++){
      $out .= $this->mac[$i-1];
      if (@($i % $digit) == 0 ) $out .= $sep;
    }
    switch ($output) {
      case 'normal':
        return rtrim($out,$sep);
        break;
      case 'upper':
        return  strtoupper(rtrim ($out,$sep));
        break;
      case 'lower':
        return  strtolower(rtrim ($out,$sep));
        break;
      default:
        $this->error('No valid output option : '.$out);
  } }

  public function GetMacAddr($ifname = 'eth0') {
    switch ($_SERVER["OS"]) {
      case 'FreeBSD':
        $command_name = "/sbin/ifconfig $ifname ";
        $condition = "/ether [0-9A-F:]*/i";
        $linefeed = "\n";
        break;
      case 'Windows_NT':
        $command_name = "ipconfig /all ";
        $condition = "/Physical address[0-9 a-f :-]*|Indirizzo fisico[0-9 a-f :-]*/i";
        $linefeed = "<br>";
        break; 
      default:
        $command_name = "/sbin/ifconfig $ifname  | grep HWadd";
        $condition = "/HWaddr (\S+)/i";
        $linefeed = "\n";
        break;
    }
    exec($command_name , $command_result);

    $MacAdr = "";
    foreach($command_result as $value) {
      if(preg_match($condition, $value, $match)) {
        $MacAdr = substr($value, -17);
        break;
    } }
/*
    var_dump($command_name);
    echo "<br><br>";
    var_dump($condition);
    echo "<br><br>";
    var_dump($command_result);
    echo "<br><br>";
    var_dump($match);
    echo "<br><br>";
    var_dump($value);
    echo "<br><br>";
    var_dump($MacAdr);
    echo "<br><br>";
*/
    if ($MacAdr) return $MacAdr;
    else return "(none)";
  }

  function error($msg){
    trigger_error("[Class MacAddress]: " . $msg , E_USER_ERROR);
    echo "[Class MacAddress]: " . $msg ."\n";
} }
?>

buon "commento" a tutti e grazie
marino
 
Ultima modifica:

Longo8

Utente Attivo
28 Mar 2011
1.694
0
36
Marino: Penso sia meglio iniziare un'altra discussione, magari nella sezione script.

Per quanto riguarda il thread in questione:
"Identificare pc univocamente" la risposta è NO e, come già spiegato da flameseeker, quelli sono casi particolari in quanto per comunicare in una rete ethernet ci si basa sull'indirizzo mac ma si sta parlando d'altro :)
 

Discussioni simili