function GetIpAddress: string;
var
  wVersionRequested: WORD;
  wsaData: TWSAData;
  p: PHostEnt;
  s: array[0..128] of Char;
begin
  wVersionRequested := MAKEWORD(1, 1);
  WSAStartup(wVersionRequested, wsaData);
  try
    GetHostName(@s, 128);
    p := GetHostByName(@s);
   {Get the IpAddress}
//    Result := StrPas(iNet_ntoa(PInAddr(p^.h_addr_list^)^));
  finally
    WSACleanup
  end
end;function GetTheComputerName: string;
var
  ComputerName: array [0..MAX_COMPUTERNAME_LENGTH] of Char;
  nSize: DWORD;
begin
  nSize := MAX_COMPUTERNAME_LENGTH;
  FillChar(ComputerName, MAX_COMPUTERNAME_LENGTH, 0);
  GetComputerName(ComputerName, nSize);
  Result := ComputerName
end;

解决方案 »

  1.   

    第一函数有些问题,要把注释去掉。同时需要uses winsock
    function GetIpAddress: string;
    var
      wVersionRequested: WORD;
      wsaData: TWSAData;
      p: PHostEnt;
      s: array[0..128] of Char;
    begin
      wVersionRequested := MAKEWORD(1, 1);
      WSAStartup(wVersionRequested, wsaData);
      try
        GetHostName(@s, 128);
        p := GetHostByName(@s);
      {Get the IpAddress}
        Result := StrPas(iNet_ntoa(PInAddr(p^.h_addr_list^)^));
      finally
        WSACleanup
      end
    end;
      

  2.   

    #include <Afxinet.h>char szhostname[128];
    CString m_hostname,str;
    if( gethostname(szhostname, 128) == 0 )
    {
     struct hostent * phost;
     int i;
     phost = gethostbyname(szhostname);
     m_hostname=szhostname;
    i=0;
    int j;
    int h_length=4;
    for( j = 0; j<h_length; j++ )
    {
      CString addr;
      if( j > 0 )
      str += ".";
      addr.Format("%u", (unsigned int)((unsigned char*)phost->h_addr_list[i])[j]);
      str += addr;
    }
    }
    str就是地址