谢谢~

解决方案 »

  1.   

    var
      ip : array[0..3] of word;
      Vip : string;
      i,j : integer;
    begin
      Vip := trim(edit1.text);
      i := pos('.',vip);
      try
        if (i<4) and (i>1) then
        begin
          ip[0] := strtoint(copy(vip,1,i-1));
          j := 1;
          Delete(vip,1,i);
          i := pos('.',vip);
          if (i<4) and (i>1) then
          begin
            ip[1] := strtoint(copy(vip,1,i-1));
            j := 2;
            Delete(vip,1,i);
            i := pos('.',vip);
            if (i<4) and (i>1) then
            begin
              ip[2] := strtoint(copy(vip,1,i-1));
              j := 3;
              Delete(vip,1,i);
              i := pos('.',vip);
              if i>0 then
              begin
                ip[3] := strtoint(copy(vip,1,i-1));
              end
              else
              begin
                ShowMessage('1');
              end;
            end
            else
            begin
              ShowMessage('1');
            end;
          end
          else
          begin
            ShowMessage('1');
          end;
        end
        else
        begin
          ShowMessage('1');
        end;
      except
        ShowMessage('1');
      end;大概思路是了,自己调一下吧
      

  2.   

    function CheckIP(IPStr : String) : boolean;
    var
      vStr : String;
      i, iNum : Integer;
    begin
      vStr := IPStr + '.';
      for i := 0 to 3 do
      begin
        try
          if Pos('.', vStr) >0 then
          begin
            iNum := StrToInt(Copy(vStr, 1, Pos('.', vStr) - 1));
            if iNum >=255 then
            begin
              Result := False;
              Break;
            end;
            vStr := Copy(vStr, Pos('.', vStr) + 1, Length(vStr));
          end
          else begin
            Result := False;
            Break;
          end;
        except
          Result := False;
          Break;
        end;
      end;
    end;调用:
      if CheckIP(Edit1.Text) then
        ShowMessage('yes')
      else ShowMessage('no');
      

  3.   

    修改一下:
    function CheckIP(IPStr : String) : boolean;
    var
      vStr : String;
      i, iNum : Integer;
    begin
      vStr := IPStr + '.';
      for i := 0 to 3 do
      begin
        try
          if Pos('.', vStr) >0 then
          begin
            iNum := StrToInt(Copy(vStr, 1, Pos('.', vStr) - 1));
            if iNum >255 or iNum <0 then
            begin
              Result := False;
              Break;
            end;
            vStr := Copy(vStr, Pos('.', vStr) + 1, Length(vStr));
          end
          else begin
            Result := False;
            Break;
          end;
        except
          Result := False;
          Break;
        end;
      end;
    end;调用:
      if CheckIP(Edit1.Text) then
        ShowMessage('yes')
      else ShowMessage('no');
      

  4.   

    //  判断是否合法的IP地址  是,返回True,否则返回Falsefunction IsValidIP(const IP: string): Boolean;
    var
      Ar: TStringDynArray;
      i: integer;
    begin
      result := False;
      Ar := SplitString(IP, '.');
      if Length(Ar) <> 4 then Exit;
      for i := Low(Ar) to High(Ar) do
      try
        if not (StrToInt(Ar[i]) in [0..255]) then Exit;
      except
        Exit;
      end;
      result := True;
    end;
      

  5.   

    uses winsock;if inet_addr(pchar(IPString)) <> -1 then
      showmessage('合法IP')
    else  showmessage('非法IP');
      

  6.   

    我上面的函数可以检测掩码,Idle_(阿呆)可能也会给你带来好方法,
    你不妨一试!