如IP:127.0.0.1
判断是否包含在IP段127.0.0.0-127.33.33.0 这个IP段内。

解决方案 »

  1.   


    uses winsock;function IpInScope(Ip, IpStart, IpEnd: string): Boolean;
    var
      nIp, nIpStart, nIpEnd: Integer;
    begin
      nIpStart:=ntohl(inet_addr(PChar(IpStart)));
      nIpEnd:=ntohl(inet_addr(PChar(IpEnd)));
      nIp:=ntohl(inet_addr(PChar(Ip)));
      Result:=(Ip>=IpStart)and(Ip<=IpEnd);
    end;
    ....
      if IpInScope('127.0.0.1','127.0.0.1','127.33.33.0') then
      begin
        ShowMessage('ok');
      end;
      

  2.   

    帮楼上的修改一下笔误:function IpInScope(Ip, IpStart, IpEnd: string): Boolean;
    var
      nIp, nIpStart, nIpEnd: DWORD;
    begin
      nIpStart := ntohl(inet_addr(PChar(IpStart)));
      nIpEnd := ntohl(inet_addr(PChar(IpEnd)));
      nIp := ntohl(inet_addr(PChar(Ip)));
      Result := (nIp >= nIpStart) and (nIp <= nIpEnd);
    end;