- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
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;