Autor Beitrag
longhugo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Dephi 7, WinXP, C++
BeitragVerfasst: Fr 14.10.05 09:22 
Hi Leute,

wie kann man die MAC Addresse einer NIC auslesen? Bitte nicht auf die bisherigen posts verweisen. Dieser Code ist ja gut und schön, liefert aber nur die MAC, wenn die Karte auch connected ist. Zieht man das Kabel, ist die MAC 0-0-0-0...Das gilt auch für die Code Beispiele von Torry oder den SChweizern....(achso: das mit der 0-0-0-0 gilt nur für NT, XP und 2000er Systeme in 98 funzts)

Ich brauche aber die Hardware NIC bzw. MAC Adresse zwecks Inventur und das auch ohne physische Verbindung. Hat jemand noch n Code Snippi? Gibts n Win API?

Ciao
Hugo
ps: hab mir auch Jedi JVComputerInfoEx angesehen...leider keine MAC Info :(

Moderiert von user profile iconTino: Titel überarbeitet und überflüssige Zeilenumbrüche entfernt.
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 14.10.05 10:16 
Darauf habe ich noch nie geachtet:/, was sagt denn ipconfig /all, wird da auch 0.0.0.0 angezeigt?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 14.10.05 10:59 
Moin!

Jau, das ist ne Lösung, ipconfig /all und Ausgabe pipen. :wink:

Was ist denn mit der IP-Helper-API, da auch nix drin (hab´s grad nicht nur Hand)? MSDN schon durchforstet?

cu
Narses
longhugo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Dephi 7, WinXP, C++
BeitragVerfasst: Fr 14.10.05 12:30 
ich denke das mit ipconfig /all sollte genügen...
vor allem hat man ja auf einen Schlag alle NICs im
Rechner...
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Fr 14.10.05 12:35 
Aber wenn das mit ipconfig /all dann wird es bestimmt auch eine passende API dafür geben. Das wäre wohl der bessere Weg.

Lg Martin
longhugo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Dephi 7, WinXP, C++
BeitragVerfasst: Fr 14.10.05 12:44 
ja...kennt jemand die API? Weil mir ist gerade noch ein Problem mit ipconfig eingefallen.
shell> ipconfig/all > mac.txt -> jetzt müsste ich ja die mac.txt parsen und die MAC
rausfiltern. Soweit kein Problem. Aber was ist, wenn die Language auf English eingestellt ist.
D.h. ich müsste im Parser praktisch die Zeile "Physikalische Addresse" auch
gegen die anderen Sprachen abchecken...huha das is mir dann doch zu krass...

LG
Hugo
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 14.10.05 12:54 
Du musst (außer für chinesisch oder so :wink: ) gar nix an Sprachen anpassen, du entfernst erstmal alle Leerzeichen am Anfang der Zeilen (Trim für jede Zeile aufrufen), und dann die Zeile mit MAC am Anfang suchen...

//EDIT: oops, ich bin mit nbtstat durcheinander gekommen...
Ich hab nämlich die MACs ausgelesen, aber auch die im gesamten Netzwerk, und das geht nur mit nbtstat...


Zuletzt bearbeitet von jaenicke am Fr 14.10.05 13:01, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 14.10.05 12:55 
Moin!

user profile iconlonghugo hat folgendes geschrieben:
shell> ipconfig/all > mac.txt -> jetzt müsste ich ja die mac.txt parsen und die MAC rausfiltern. Soweit kein Problem. Aber was ist, wenn die Language auf English eingestellt ist.

Hä? Hier ein Parser-Quickhack:
ausblenden volle Höhe Delphi-Quelltext
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:
30:
31:
32:
33:
34:
procedure TForm1.Button1Click(Sender: TObject);
  var
    Datei,
    Zeile: TStringList;
    i: Integer;
    MAC: String;

  function IsMAC(const S: String): Boolean;
    const
      OK: Set of Char = ['0'..'9','A'..'F','-'];
    var
      i: Integer;
  begin
    Result := TRUE;
    for i := 1 to Length(S) do
      Result := (Result and (UpCase(S[i]) in OK));
  end;

begin
  Datei := TStringList.Create;
  Zeile := TStringList.Create;
  Datei.LoadFromFile('D:\MAC.TXT');
  for i := 0 to Datei.Count-1 do begin
    Zeile.CommaText := Datei.Strings[i];
    if (Zeile.Count > 2then begin
      MAC := Zeile.Strings[Zeile.Count-1];
      if (Length(MAC) = 17then
        if (IsMAC(MAC)) then
          ListBox1.Items.Add(MAC);
    end;
  end;
  Zeile.Free;
  Datei.Free;
end;

cu
Narses
longhugo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Dephi 7, WinXP, C++
BeitragVerfasst: Fr 14.10.05 13:01 
ja klasse - ich hab nicht daran gedacht, dass die MAC Addresse mit "-" ausgegeben wird
statt mit "." wie die IP Addressen. Damit kann man ja prima unterscheiden

Danke narses
ps: Ich mach das Thema aber noch nicht zu, falls noch jemand das mit dem API rausfindet...
longhugo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Dephi 7, WinXP, C++
BeitragVerfasst: Fr 14.10.05 23:30 
So nu hab ich's dann doch gefunden. API = CoCreateGUID. Die ist Bestandteil der RemoteProcedureCallRuntime DLL (RPCRT.DLL). Ab Win2000 hat sich der API Aufruf geändert. Deshalb die Versionsprüfung. Funzt wunderbar.

ausblenden Delphi-Quelltext
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:
30:
Type
 TGUID=record
  A,B:word;
  D,M,S:word;
  MAC:array[1..6of byte;
 end;

function GetMACAddress():String;
var
 UuidCreateFunc : function (var guid: TGUID):HResult;stdcall;
 handle : THandle;
 g:TGUID;
 WinVer:_OSVersionInfoA;
 i:integer;
 ErrCode: HResult;
begin
 WinVer.dwOSVersionInfoSize := sizeof(WinVer);
 getversionex(WinVer);

 handle := LoadLibrary('RPCRT4.DLL');
 if WinVer.dwMajorVersion >= 5 then {Windows 2000 }
  @UuidCreateFunc := GetProcAddress(Handle, 'UuidCreateSequential')
 else
  @UuidCreateFunc := GetProcAddress(Handle, 'UuidCreate') ;

 UuidCreateFunc(g);
 result:='';
 for i:=1 to 6 do
   result:=result+IntToHex(g.MAC[i],2);
end;



Bis denn!
Euer Hugo
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 15.10.05 00:16 
Moin!

Naja, und was is, wenn du mehrere Netzwerkkarten im Rechner hast... ? :wink:

cu
Narses
longhugo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Dephi 7, WinXP, C++
BeitragVerfasst: Sa 15.10.05 07:40 
tja das ist der Wehrmutstropfen. Die Routine liefert immer nur die erste Mac. Aber zumindest haben wir hier für das Forum ja jetzt zwei Lösungen und es gibt ja auch noch die dritte über NCB - mit Kabel drin (s.o.) :)

Trotzdem wäre eine komplette Doku der API klasse - also falls sie jemand hat?

Cheers
Hugo