1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| // J.P code pour trouver adresse MAC d'une adresse I.P distante
// à rajouter si besoin
uses Regexpr,process;
// ===========================================
var reponse : string;
re: TRegExpr;
i: integer;
adresseDistante : string;
begin
adresseDistante := '192.168.0.1';
RunCommand('ping',['-n','1',adresseDistante],reponse);
//ShowMessage(reponse);
if pos('Impossible',reponse) > 0 then ShowMessage('Adresse non joignable')else
begin
RunCommand('arp',['-a',adresseDistante],reponse);
//ShowMessage(reponse);
try
re := TRegExpr.Create;
// motif qui correspond à une adresse MAC sous windows
re.Expression := '[0-9a-f]{2}-[0-9a-f]{2}-[0-9a-f]{2}-' +
'[0-9a-f]{2}-[0-9a-f]{2}-[0-9a-f]{2}';
if re.Exec(reponse) then
showMessage('adresse MAC de ' + adresseDistante + ' : ' + re.Match[0]) else
ShowMessage('adresse MAC non trouvée');
finally
re.Free;
end;
end;
end; |