判断IP地址是否非法的代码:

 1 function   TForm1.IsIPString(IPStr:   string):   Boolean;
2 var
3 i,DotNum:integer;
4 Tmpstr:string;
5 begin
6 Result:=true;
7 DotNum:=0;
8 for i:=1 to Length(IPStr) do
9 Case IPStr[i] of
10 '0'..'9','.':
11 begin
12 if IPStr[i]<>'.' then
13 begin
14 Tmpstr:=Tmpstr+IPStr[i];
15 if StrtoInt(tmpstr)>255 then
16 begin
17 Result:=False;
18 exit;
19 end;
20 end
21 else
22 begin
23 if (TmpStr='')and(DotNum>0) then //如果连续2个点的情况
24 begin
25 Result:=False;
26 Exit;
27 end;
28 Tmpstr:='';
29 DotNum:=DotNum+1;
30 end;
31 end;
32 else
33 begin Result:=false; exit; end;
34 end;
35 if DotNum<>3 then Result:=False;
36 end;

 

posted on 2012-03-06 16:33  东睿软件工作室  阅读(776)  评论(0编辑  收藏  举报