Getting the Physical Address for Windows?[resolved] lazarus / 13-General ---------------------------------------------------------------------- Drakon · 2009-10-25 16:45 Hello, my application need to obtain the physical address of network card, however, the functions I used in Delphi, are not working, can anyone help me with this problem? If you have an example using the Indy is also helpful. ---------------------------------------------------------------------- Marc · 2009-10-25 17:41 what do you use in delphi ? ---------------------------------------------------------------------- Mujie · 2009-10-26 05:21 Place a TButton at your Form, then use this code : Code: [Select]uses .......... , Winsock; .......... function getIPs: Tstrings; type   TaPInAddr = array[0..10] of PInAddr;   PaPInAddr = ^TaPInAddr; var   phe: PHostEnt;   pptr: PaPInAddr;   Buffer: array[0..63] of Char;   I: Integer;   GInitData: TWSAData; begin   WSAStartup($101, GInitData);   Result := TstringList.Create;   Result.Clear;   GetHostName(Buffer, SizeOf(Buffer));   phe := GetHostByName(buffer);   if phe = nil then Exit;   pPtr := PaPInAddr(phe^.h_addr_list);   I    := 0;   while pPtr^[I] <> nil do   begin     Result.Add(inet_ntoa(pptr^[I]^));     Inc(I);   end;   WSACleanup; end; procedure TForm1.Button1Click(Sender: TObject); begin   ShowMessage(GetIps.text); end; .......... Taken from http://www.delphitricks.com/source- code/internet/get_your_own_ip_address.html And it works charm! ---------------------------------------------------------------------- Drakon · 2009-10-26 09:10 I decided with the following function: Code: [Select] function CoCreateGuid(var guid: TGUID): HResult; stdcall; far external 'ole32.dll'; function Get_MACAddress: string; var   g: TGUID;   i: Byte; begin   Result := '';   CoCreateGUID(g);   for i := 2 to 7 do     Result := Result + IntToHex(g.D4[i], 2); end; I tried several others, and none of them worked, perhaps to get this has worked because it uses a dll as a basis. Font:http://www.scalabium.com/faq/dct0088.htm ---------------------------------------------------------------------- Marc · 2009-10-26 10:56 using CoCreateGuid relies on the fact that older versions of that function use a mac address (from which adapter if you have more) when creating a GUID. Newer implementations might not use it anymore to anonemize the creator of the GUID. To enumerate adapters on windows you can use something like (stripped so it might not compile)Code: [Select]var   search: TInAddr;   QSet: TWsaQuerySet;   QSetLookup: record     Info: TWsaQuerySet;     Data: array[0..1023] of Byte; // temp buffer to store additional data   end;   Protos: TAfProtocols;   hLookup: THandle; begin       ZeroMemory(@QSet, SizeOf(QSet));       QSet.dwSize := SizeOf(QSet);       QSet.dwNameSpace := NS_ALL;       QSet.lpServiceClassId := @SVCID_HOSTNAME;       Protos.iAddressFamily := AF_INET;       Protos.iProtocol := IPPROTO_TCP;       QSet.dwNumberOfProtocols := 1;       QSet.lpafpProtocols := @Protos;       hLookup := 0;       Search.S_addr := 0;       if WSALookupServiceBegin(@QSet, LUP_RETURN_ADDR or LUP_RETURN_NAME, hLookup) <> 0       then begin         //Failed to begin lookup service         Exit;       end;       First := True;       while True do       begin         len := SizeOf(QSetLookup);         FillChar(QSetLookup, 0, len);         if WSALookupServiceNext(hLookup, 0, len,  @QSetLookup) <> 0         then begin           //if First           //then; //Failed to retieve interface address           Break;         end;         First := False;         if QSetLookup.Info.dwNumberOfCsAddrs = 0 then Continue;         Search := PSockAddrIn(QSetLookup.Info.lpcsaBuffer^.RemoteAddr. lpSockaddr)^.sin_Addr;       end;       WSALookupServiceEnd(hLookup);