clientsocket.address := 'xxx.xxx.xxx.xxx'自己做好了.
  
   子网掩码:是不是一样?

解决方案 »

  1.   

       我问 子网掩码:是不是一样
      
        一样的话,可以用winapi 网络资源搜索,函数来搜索啊!
      

  2.   

    用实现的话,可以通过创建多个线程去扫描同一段的IP。当然这样做可能会耗费系统很多的资源,一般应控制为前三段IP相同,只针对最后一段的情况。
    具体可参考某位高人写的程序:constructor TIPThred.Create(IP: String);
    begin
      FIP := IP;
      inherited Create(true);
      FreeOnTerminate:=true;
      Resume;
    end;procedure TIPThred.Execute;
    const
      Size = 56;
      TimeOut = 1000;
    var
      Address: DWord;                     // Address of host to contact
      HostName, HostIP: String;           // Name and dotted IP of host to contact
      Phe: PHostEnt;                      // HostEntry buffer for name lookup
      BufferSize, nPkts: Integer;
      pReqData, pData: Pointer;
      pIPE: PIcmpEchoReply;               // ICMP Echo reply buffer
      IPOpt: TIPOptionInformation;        // IP Options for packet to send  i: integer;
    begin
      // Do a lookup  Address := inet_addr(PChar(FIP));  if (Address = INADDR_NONE) then begin
        Phe := GetHostByName(PChar(FIP));
        if Phe = Nil then
        begin
          ;
          //ShowError(WSAGetLastError)
        end
        else begin
          Address := longint(plongint(Phe^.h_addr_list^)^);
          HostName := Phe^.h_name;
          HostIP := StrPas(inet_ntoa(TInAddr(Address)));
        end;
      end
      else begin
        Phe := GetHostByAddr(@Address, 4, PF_INET);
        if Phe = Nil then
        begin
          ;
          //ShowError(WSAGetLastError)
        end
        else begin
          HostName := Phe^.h_name;
          HostIP := StrPas(inet_ntoa(TInAddr(Address)));
        end;
      end;  if Address = INADDR_NONE then
      begin
        ;//Memo1.Lines.Add('Cannot resolve hostname ' + Edit1.Text);
      end
      else
      begin
        //Memo1.Lines.Add('Sending ' + IntToStr(Size) + ' bytes to ' +
          //HostName + ' (' + HostIP + ')');    // Get some data buffer space and put something in the packet to send
        BufferSize := SizeOf(TICMPEchoReply) + Size;
        GetMem(pReqData, Size);
        GetMem(pData, Size);
        GetMem(pIPE, BufferSize);
        FillChar(pReqData^, Size, $AA);
        pIPE^.Data := pData;    // Finally Send the packet
        FillChar(IPOpt, SizeOf(IPOpt), 0);
        IPOpt.TTL := 64;
        NPkts := IcmpSendEcho(hICMP, Address, pReqData, Size,
          @IPOpt, pIPE, BufferSize, TimeOut);
        if NPkts = 0 then
        begin
          //ShowError(GetLastError)
        end
        else begin
          //ShowMessage('ok');
          HostIP := StrPas(inet_ntoa(TInAddr(pIPE^.Address)));
          IPMsg := HostIP;
          for i := length(HostIP) to 16 do
          begin
            IPMsg := IPMsg + ' ';
          end;
          IPMsg := IPMsg + HostName;
          Synchronize(DispIPMsg);
          //Memo1.Lines.Add('Received ' + IntToStr(pIPE^.DataSize) +
            //' bytes from ' + HostIP +
            //' in ' + IntToStr(pIPE^.RTT) + ' msecs')
        end;    // Free those buffers
        FreeMem(pIPE);
        FreeMem(pData);
        FreeMem(pReqData);
      end;
    end;
      

  3.   

    airhorse阿,子网掩码当然一样。请问winapi 网络资源搜索,函数?是什么?谢谢!
      

  4.   

    按照高人的程序,使用inet_addr可以把计算机名称、IP地址全部取回。试一下吧!