IPv6相当于扫描子网?

时间:2017-10-05 15:53:18

标签: ios delphi ipv6 indy delphi-10-seattle

我有一段代码扫描用户网络中的256个IPv4地址,检查每个地址是否有特定的TCP端口,并检查它是否是可以连接的服务器。这个概念很简单......

type
  TIPAddressV4 = record
    IP1: Byte;
    IP2: Byte;
    IP3: Byte;
    IP4: Byte;
    function AsString: String;
  end;

  TServerResult = class(TObject)
  //Some proprietary properties...
  end;

  TServerSearchCallback = Reference to procedure(AItem: TServerResult);

  TProgressCallback = Reference to procedure(ACurrent, AMax: Integer);

procedure ServerSearch(ACallback: TServerSearchCallback; AProgressCallback: TProgressCallback);
begin
  TThread.CreateAnonymousThread(
    procedure
    var
      Cli: TIdHTTP;
      Url, Res, T: String;
      IP: TIPAddressV4;
      X: Integer;
      O: ISuperObject;
      S: TServerResult;
    begin
      IP:= GetThisDeviceIPv4Address;
      Cli:= TIdHTTP.Create(nil);
      try
        Cli.ConnectTimeout:= 50;
        //Iterate every possible IPv4 address in same range...
        for X := 0 to 255 do begin
          //Concatenate IP address and URL...
          T:= IntToStr(IP.IP1)+'.'+IntToStr(IP.IP2)+'.'+IntToStr(IP.IP3)+'.'+IntToStr(X);
          Url:= 'http://'+T+':12345/ServerInfo';
          try
            //Test HTTP GET request and check if JSON...
            Res:= Cli.Get(Url);
            O:= SO(Res);
            if O <> nil then begin
              //Check if JSON is really expected format...
              if O.S['Name'] = 'My Unique Name' then begin
                //Trigger callback...
                S:= TServerResult.Create;
                try

                  //Populate with proprietary properties...
                  S.Host:= O.S['host'];
                  //...

                finally
                  TThread.Synchronize(TThread.CurrentThread,
                    procedure
                    begin
                      if Assigned(ACallback) then
                        ACallback(S);
                    end);
                  //Object is NOT free'd here, receiver takes ownership.
                end;
              end;
            end;
          except
            on E: Exception do begin
              //We don't care about handling exceptions here...
            end;
          end;
          //Used for progress bar...
          TThread.Synchronize(TThread.CurrentThread,
            procedure
            begin
              if Assigned(AProgressCallback) then
                AProgressCallback(X, 255);
            end);
        end;
      finally
        Cli.Free;
      end;
    end).Start;
end;

例如,如果此设备的IP为192.168.0.5,它将扫描从192.168.0.0到192.168.0.255的IP地址,以查找它可以连接的特定服务器。

问题出现在Apple需要IPv6支持的事实上。此代码当然仅支持IPv4。 IPv6的工作原理完全不同,更不用说, IPv4 IPv6都可以找到单个服务器。

我需要做些什么来使这也适用于IPv6,从而满足Apple的IPv6支持要求?

修改

我实际上认为,对于Apple的要求,这可能并非绝对必要。当然,与API进行一般性沟通。但是对于应用程序的这个特殊功能,我怀疑它是否属于这个要求的范畴。

0 个答案:

没有答案