Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

The Fast and Best way to get a local IP Address

Title: The Fast and Best way to get a local IP Address Question: How get the local IP Address easy and fast? "Como obter o endereo ip local de maneira rpida e fcil?" Answer: See: "Veja:" ------------------------------------------------------------------ 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; ------------------------------------------------------------------ This function not requires special units or triks to make your work "Esta funo no requer nada em especial para fazer seu trabalho" :-) Grson, from Brazil. "Grson, do Brasil"