delphi中判断IP地址输入的合法性

Posted on 2020-01-02 08:40  阿骏骏  阅读(369)  评论(0编辑  收藏  举报
function GetSubStrCount(sSubStr, sParentStr: string): integer;
begin
  Result := 0;
  while Pos(UpperCase(sSubStr), UpperCase(sParentStr)) <> 0 do
    begin
      sParentStr := Copy(sParentStr, Pos(sSubStr, sParentStr) + 1, Length(sParentStr)); 
      Result := Result + 1;
    end;

end;

function IsIp(ip:string):boolean;
begin
  if (GetSubStrCount('.', IP) = 3) and (Longword(inet_addr(PAnsiChar(AnsiString(IP)))) <> INADDR_NONE) then
    Result := True
  else
    Result := False;
end;

Copyright © 2024 阿骏骏
Powered by .NET 8.0 on Kubernetes