如题,请高手指点一二,另外请问如何获得网络上计算机的IP?

解决方案 »

  1.   

    检测机器是否登入网络
    function CheckMacAttachNet: Boolean;
    begin
      Result := False;
      if GetSystemMetrics(SM_NETWORK) <> 0 then
        Result := True;
    end;{=================================================================
      功  能:  检测计算机是否上网
      参  数:  无
      返回值:  成功:  True  失败: False;
      备 注:   uses Wininet
      版 本:
         1.0  2002/10/07 13:33:00
    =================================================================}
    function InternetConnected: Boolean;
    const
      // local system uses a modem to connect to the Internet.
      INTERNET_CONNECTION_MODEM      = 1;
      // local system uses a local area network to connect to the Internet.
      INTERNET_CONNECTION_LAN        = 2;
      // local system uses a proxy server to connect to the Internet.
      INTERNET_CONNECTION_PROXY      = 4;
      // local system's modem is busy with a non-Internet connection.
      INTERNET_CONNECTION_MODEM_BUSY = 8;
    var
      dwConnectionTypes : DWORD;
    begin
      dwConnectionTypes := INTERNET_CONNECTION_MODEM+ INTERNET_CONNECTION_LAN
      + INTERNET_CONNECTION_PROXY;
      Result := InternetGetConnectedState(@dwConnectionTypes, 0);
    end;
      

  2.   

    将某一主机域名解析为IP地址。
    使用 WinSock 单元;
    过程如下:
    function HostToIP(Name: string; var Ip: string): Boolean;
    var
      wsdata : TWSAData;
      hostName : array [0..255] of char;
      hostEnt : PHostEnt;
      addr : PChar;
    begin
      WSAStartup ($0101, wsdata);
      try
        gethostname (hostName, sizeof (hostName));
        StrPCopy(hostName, Name);
        hostEnt := gethostbyname (hostName);
        if Assigned (hostEnt) then
          if Assigned (hostEnt^.h_addr_list) then begin
            addr := hostEnt^.h_addr_list^;
            if Assigned (addr) then begin
              IP := Format ('%d.%d.%d.%d', [byte (addr [0]),
              byte (addr [1]), byte (addr [2]), byte (addr [3])]);
              Result := True;
            end
            else
              Result := False;
          end
          else
            Result := False
        else begin
          Result := False;
        end;
      finally
        WSACleanup;
      end
    end;