Programming/Delphi

로컬 아이피 알아내기

통통만두 2010. 12. 16. 20:34
반응형
function GetLocalIP : String;
var
   WSAData: TWSAData;
   HostName, IPAddress: String;
   HostEnt: PHostEnt;
begin
   WSAStartup(2, WSAData);
   SetLength(HostName, 255);
   GetHostname(PChar(HostName), 255);
   SetLength(HostName, StrLen(PChar(HostName)));
   HostEnt := GetHostByName(PChar(HostName));

   with HostEnt^ do
     IPAddress := Format('%d.%d.%d.%d',[Byte(h_addr^[0]), Byte(h_addr^[1]),
     Byte(h_addr^[2]), Byte(h_addr^[3])]);

   WSACleanup;
   Result := IPAddress;
end;
반응형