检查IP地址是否有效(delphi)

 
Function Checkip(const Ip:String):byte;
var
  i,k:Integer;
  s1:String;
begin
  Result:=0;
  s1:=Ip;
  i:= Pos('.',s1);
  s1 := s1 + '.';
  while i > 0 do
  begin
    if not Length(Copy(s1,1,i)) in [2..4] then
      break;
    k:=StrTointDef(Copy(s1,1,i-1),-1);
    if (k<0) or (k>255) then
      Break;
    inc(Result);
    if Result>4 then
      Exit;
    system.Delete(s1,1,i);
    i:= Pos('.',s1);
  end;
end;

posted @ 2012-05-03 08:25  yoogoo  阅读(1416)  评论(0编辑  收藏  举报