Can not detect if the MAC address is real, you first need to understand what a MAC address is, as per wiki:
The MAC address ( Media Access Control ) is a physical address associated with the communication interface, which connects a device to the network. The MAC is a "single" address, there are no two ports with the same numbering, it is used for access control in computer networks. Its identification is recorded in hardware, that is, in the ROM of the network card of equipment such as desktops, notebooks, routers, smartphones, tablets, network printers, etc.
Then understand that:
- The physical address can only be observed in LAN
- Will not be public (or propagated to the internet)
- It will be available through the ARP mapping.
- You may be able to make the data public, but this will be the specific device that you have set up and "forced / made available"
Note that even getting it via a language running at a "lower level" and LAN was a little tricky for me ( Is it possible to determine the hardware address of the router? )
I was forced to use commands like (Windows operating system):
-
Get all addresses connected on the same network and "visible":
arp -a
Output:
Interface: 192.168.2.54 --- 0xe
Endereço IP Endereço físico Tipo
192.168.2.1 b8-38-61-5d-84-28 dinâmico
192.168.2.2 48-f8-b3-bc-45-d1 dinâmico
192.168.2.4 c0-4a-00-87-aa-d6 dinâmico
192.168.2.150 88-51-fb-22-31-9a dinâmico
192.168.2.255 ff-ff-ff-ff-ff-ff estático
224.0.0.2 01-00-5e-00-00-02 estático
224.0.0.252 01-00-5e-00-00-fc estático
239.255.255.250 01-00-5e-7f-ff-fa estático
255.255.255.255 ff-ff-ff-ff-ff-ff estático
-
Get address from a specified gateway or ip:
arp -a 129.168.0.1
Output:
Interface: 192.168.2.54 --- 0xe
Endereço IP Endereço físico Tipo
192.168.2.1 b8-38-61-5d-84-28 dinâmico
-
Get data with ipconfig:
ipconfig /all
Output:
Windows IP Configuration
Nome do host. . . . . . . . . . . . . . . . : guilherme-PC
Sufixo DNS primário . . . . . . . . . . . . :
Tipo de nó. . . . . . . . . . . . . . . . . : híbrido
Roteamento de IP ativado. . . . . . . . . . : não
Proxy WINS ativado. . . . . . . . . . . . . : não
Lista de pesquisa de sufixo DNS . . . . . . : home
Wireless Network Adapter Wireless Network Connection:
Sufixo DNS específico de conexão. . . . . . : router5d8428.com
Descrição . . . . . . . . . . . . . . . . . : Intel(R) WiFi Link 1000 BGN
Endereço Físico . . . . . . . . . . . . . . : 00-26-C7-D8-E8-08
DHCP Habilitado . . . . . . . . . . . . . . : Sim
Configuração Automática Habilitada. . . . . : Sim
Endereço IPv6 de link local . . . . . . . . : fe80::34d0:d738:4aab:83cf%14(Preferencial)
Endereço IPv4. . . . . . . . . . . . . . . : 192.168.2.54(Preferencial)
Máscara de Sub-rede . . . . . . . . . . . . : 255.255.255.0
Concessão Obtida. . . . . . . . . . . . . . : quinta-feira, 17 de novembro de 2016 15:41:07
Concessão Expira. . . . . . . . . . . . . . : domingo, 20 de novembro de 2016 03:57:36
Gateway Padrão. . . . . . . . . . . . . . . : 192.168.2.1
Servidor DHCP . . . . . . . . . . . . . . . : 192.168.2.1
IAID de DHCPv6. . . . . . . . . . . . . . . : 184559303
DUID de Cliente DHCPv6. . . . . . . . . . . : 00-01-00-01-1F-8D-3F-74-3C-4A-92-4E-40-CC
Servidores DNS. . . . . . . . . . . . . . . : fd37:267c:7d7a:1:204:dfff:fe8c:e72d
192.168.2.1
NetBIOS em Tcpip. . . . . . . . . . . . . . : Habilitado
Lista de pesquisa de sufixos DNS específicos da conexão: home
How is the format?
According to the wiki:
The Image below presents a simplified version of the frame used in local Ethernet networks, known as the Ethernet frame. The first address identifies the recipient of the message, that is, the receiver. The second address identifies the sender, ie the sender. Each address consists of six bytes, theoretically allowing 2⁴⁸ addresses. For example, the number 00-0C-6E-3C-D1-6D
represents an Ethernet address in hexadecimal format.
You can then validate by PHP or JavaScript the format only, using a regex like this:
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$
An example in PHP would be:
<?php
$mac_address = empty($_GET['mac_address']) ? '' : $_GET['mac_address'];
if (preg_match('#^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$#', $mac_address) > 0) {
echo 'Validou!';
} else {
echo 'Não Validou!';
}
In JavaScript:
<input placeholder="Digite seu endereço de MAC" type="text" id="mac_address" name="mac_address">
<button id="validar">Evniar</button>
<script>
function validaEnderecoFisico(endereco) {
return /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(endereco);
}
var input = document.getElementById("mac_address");
var btn = document.getElementById("validar");
btn.onclick = function() {
if (validaEnderecoFisico(input.value)) {
alert("Validou");
} else {
alert("Não validou");
return false;
}
};
</script>
However
However @Bacco pointed me to a service that can help make this link , they have a REST API that can bring you help check:
For example, go to (change your Mac address): link
Yet before using it, be aware that like the @ Bacco said :
You can not validate if it's real. It only has to validate if it is of "known brand", because not all the manufacturers respect this (and some pass for others, mainly in the market of "second line"). Virtually any 6 bytes described in hex are valid.
Some may try to pass themselves off as others.
However a simple example of using the API with PHP would be:
<?php
$enderecoMac = 'DIGITE SEU ENDEREÇO DE MAC';
$url = 'http://www.macvendorlookup.com/api/v2/' . urlencode($enderecoMac);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$curl_err = curl_errno($ch);
if ($curl_err != 0) {
$result = array( 'error' => 'Erro ao usar o CURL: ' . $curl_err );
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
$result = array( 'error' => 'Erro ao baixar: ' . $httpCode );
} else {
$result = json_decode($data);
$data = null;
}
}
curl_close($ch);
var_dump($result);