[delphi] 로컬 IP 가져오기

반응형
반응형

function Tdm.Get_LocalIP: String;
var
  WSAData : TWSAData;
  HostName: String;
  HostEnt : pHostEnt;
begin
  WSAStartup(2, WSAData);
  SetLength(HostName, 255);
  GetHostName(PChar(HostName), 255);
  SetLength(HostName, StrLen(PChar(HostName)));
  HostEnt := GetHostByName(PChar(HostName));

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

end;

 

반응형

댓글