判断IP地址是否非法!

判断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;

 

转载于:https://www.cnblogs.com/prtmon/archive/2012/03/06/2382169.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值