Ir para conteúdo
Fórum Script Brasil
  • 0

Validação De Ip


guitarmc

Pergunta

Somos da Escola técnica federal de Palmas, e estamos fazendo um projeto que necessita de validação de ip, manipulação de arquivo(editá -lo, deletá -lo) e componentes DE ftp. Gostáriamos que vocês nos dessem uma solução para se fazer validação de ip usando MASKEDIT, POIS AINDA SOMOS INICIANTES EM DELPHI E ESTAMOS COM UMA GRANDE DIFICULDADE PARA FAZER ESTE PROJETO!!

DESDE JÁ AGRADECEMOS!!!!!!!1

GUITARMC

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Tenta isso amigo:

function TForm1.IsWrongIP(ip: string): Boolean;
var
   z:integer;
   i: byte;
   st: array[1..3] of byte;
const
   ziff = ['0'..'9'];
begin
   st[1] := 0;
   st[2] := 0;
   st[3] := 0;
   z := 0;
   Result := False;
   for i := 1 to Length(ip) do if ip[i] in ziff then
   else begin
      if ip[i] = '.' then begin
         Inc(z);
         if z < 4 then st[z] := i
         else begin
            IsWrongIP := True;
            Exit;
         end;
      end else begin
         IsWrongIP := True;
         Exit;
      end;
   end;
   if (z <> 3) or (st[1] < 2) or (st[3] = Length(ip)) or
      (st[1] + 2 > st[2]) or (st[2] + 2 > st[3]) or
      (st[1] > 4) or (st[2] > st[1] + 4) or (st[3] > st[2] + 4) then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, 1, st[1] - 1));
   if (z > 255) or (ip[1] = '0') then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, st[1] + 1, st[2] - st[1] - 1));
   if (z > 255) or ((z <> 0) and (ip[st[1] + 1] = '0')) then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, st[2] + 1, st[3] - st[2] - 1));
   if (z > 255) or ((z <> 0) and (ip[st[2] + 1] = '0')) then begin
      IsWrongIP := True;
      Exit;
   end;
   z := StrToInt(Copy(ip, st[3] + 1, Length(ip) - st[3]));
   if (z > 255) or ((z <> 0) and (ip[st[3] + 1] = '0')) then begin
      IsWrongIP := True;
      Exit;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 IsWrongIP(MaskEdit1.text);
end;

falou!!! wink.gif

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...