Delphi得到自己IP我想写个隐藏的程序  得到一个动态的自己的IP不知怎么写 用控件的话 隐藏的程序怕是用不了的希望有个函数最好  
  procedure   GetHostInfo(var   Name,   Address:   string);
  var  
  WSAData:   TWSAData;
  HostEnt:   PHostEnt;
  begin
  WSAStartup(2,   WSAData);
  SetLength(Name,   255);
  Gethostname(PChar(Name),   255);
  SetLength(Name,   StrLen(PChar(Name)));
  HostEnt   :=   gethostbyname(PChar(Name));
  with   HostEnt^   do
  Address   :=   Format('%d.%d.%d.%d',[Byte(h_addr^[0]),
  Byte(h_addr^[1]),Byte(h_addr^[2]),   Byte(h_addr^[3])]);
  WSACleanup;
  end;这有个函数 小弟不知道怎么用  求解

解决方案 »

  1.   

    你那函数的用法:
    var aName,Address:string;
    begin
      GetHostInfo(aName,Address);
      showmessageFmt('计算机名:%s IP:%s',[aName,Addree]);
    end;
      

  2.   

    Indy Misc
    下面的
    IdIPWatch1.LocalIP
      

  3.   

    function GetHostIP(HostName: String): String;
    var
       buf:pChar;
       iWsaRet:Integer;
       Data:WSAData;
       hostent:PHostEnt;
    begin
       Result := '';
       iWsaRet := WSAStartup($101,Data);
       if iWsaRet<>0 then
       begin
          //ShowMessage('Socket initialize error!');
          Exit;
       end;
       buf := Allocmem(60);
       strcopy(buf,PChar(HostName));
       if Trim(buf)='' then
          gethostname(buf,60);
       hostent := gethostbyname(buf);
       Freemem(buf,60);
       if hostent=nil then
          Exit;
       Result  := inet_ntoa(pinAddr(hostent^.h_addr^)^);
       WSACleanup();
    end;调用:GetHostIP('');