Development/Delphi
로컬 IP 가져오기
코드의추억
2015. 8. 25. 13:14
function TForm1.GetLocalAddress:string; var wsaData : TWSAData; slocal : array[0..255] of AnsiChar; phos : PHostEnt; addr : PChar; begin Result := ''; if (WSAStartup(MAKEWORD(1, 1), wsaData) <> 0) then exit; if (gethostname(slocal, sizeof(slocal)) = SOCKET_ERROR) then exit; phos := gethostbyname(slocal); if phos = nil then exit; addr := PChar(phos.h_addr_list^); Result := inet_ntoa(PInAddr(addr)^); WSACleanup(); end;