Delphi 컴퓨터 이름 및 IP 주소 가져오기

1054 단어 functionDelphi

function GetComputerName:String; //       
var
  wVersionRequested : WORD;
  wsaData : TWSAData;
  p : PHostEnt; s : array[0..128] of char;
begin
  try
    wVersionRequested := MAKEWORD(1, 1); //   WinSock
    WSAStartup(wVersionRequested, wsaData); //   WinSock
    GetHostName(@s,128);
    p:=GetHostByName(@s);
    Result:=p^.h_Name;
  finally
    WSACleanup; //   WinSock
  end;
end;

function GetHostIP:String; //  IP
var
   wVersionRequested : WORD;
   wsaData : TWSAData;
   p : PHostEnt; s : array[0..128] of char; p2 : pchar;
begin
   try
      wVersionRequested := MAKEWORD(1, 1); //   WinSock
      WSAStartup(wVersionRequested, wsaData); //   WinSock
      GetHostName(@s,128);
      p:=GetHostByName(@s);
      p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
      Result:= P2;
   finally
      WSACleanup; //   WinSock
   end;
end;

좋은 웹페이지 즐겨찾기