Delphi 验证IP地址


本文整理自网络,侵删。

 
//有点老旧了,就当是学习了

function IsIPaddr(IP: string): Boolean;
var
  Node: array[0..3] of Integer;
  tIP: string;
  tNode: string;
  tPos: Integer;
  tLen: Integer;
begin
  Result := False;
  tIP := IP;
  tLen := Length(tIP);
  tPos := Pos('.', tIP);
  tNode := MidStr(tIP, 1, tPos - 1);
  tIP := MidStr(tIP, tPos + 1, tLen - tPos);
  if not TryStrToInt(tNode, Node[0]) then Exit;

  tLen := Length(tIP);
  tPos := Pos('.', tIP);
  tNode := MidStr(tIP, 1, tPos - 1);
  tIP := MidStr(tIP, tPos + 1, tLen - tPos);
  if not TryStrToInt(tNode, Node[1]) then Exit;

  tLen := Length(tIP);
  tPos := Pos('.', tIP);
  tNode := MidStr(tIP, 1, tPos - 1);
  tIP := MidStr(tIP, tPos + 1, tLen - tPos);
  if not TryStrToInt(tNode, Node[2]) then Exit;

  if not TryStrToInt(tIP, Node[3]) then Exit;
  for tLen := Low(Node) to High(Node) do begin
    if (Node[tLen] < 0) or (Node[tLen] > 255) then Exit;
  end;
  Result := True;
end;

相关阅读 >>

Delphi 如何将颜色值转换为灰度颜色值?

Delphi 2010 fastmm 内存泄露使用方法

Delphi 的内存操作函数(2): 给数组指针分配内存

Delphi 移动端使用 sqlite数据库查询

Delphi从dbgrid导出数据保存成excel文件

Delphi简单判断程序30秒没有键盘和鼠标动作示例

Delphi文件操作的一些函数

winsock 实现telnet后门

winapi 字符及字符串函数(2): charlowerbuff - 把缓冲区中指定数目的字符转小写

Delphi 用 superobject 解析淘宝上的 json 数据

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...