Parsi Coders
Check Valid IP Address - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Software Development Programming (http://parsicoders.com/forumdisplay.php?fid=37)
+--- انجمن: Pascal/Delphi (http://parsicoders.com/forumdisplay.php?fid=45)
+---- انجمن: Delphi (http://parsicoders.com/forumdisplay.php?fid=69)
+---- موضوع: Check Valid IP Address (/showthread.php?tid=420)



Check Valid IP Address - Amin_Mansouri - 06-20-2011

A simple way to check whether an IP address is valid.
کد:
function IsIPAddress(zvIPAddressID: string): boolean;
var
  ipLengthOfGroup, ipPosition, ipNoOfGroups: integer;
  ipGroupNum, Code: integer;
begin
  IsIpAddress := False;
  ipNoOfGroups := 0;
  ipLengthOfGroup := 0;
  for ipPosition := 1 to Length(zvIPAddressID) do
    case Ord(zvIPAddressID[ipPosition]) of
      48..57:
        begin
          inc(ipLengthOfGroup);
          if (ipLengthOfGroup > 3) then exit;
        end;
      46:
        begin
          inc(ipNoOfGroups);
          Val(Copy(zvIPAddressID, ipPosition - ipLengthOfGroup, ipLengthOfGroup), ipGroupNum, Code);
          if ((ipNoOfGroups > 3) or (ipLengthOfGroup = 0)) or (ipGroupNum > 255) then exit;
          ipLengthOfGroup := 0;
        end;
      else
        exit;
    end;
  Val(Copy(zvIPAddressID, ipPosition - ipLengthOfGroup, ipLengthOfGroup), ipGroupNum, Code);
  IsIPAddress := (ipNoOfGroups = 3) and (ipLengthOfGroup > 0) and (ipGroupNum < 256);
end;
در سورس بالا که با دلفی نوشته است میتونید چک کنید ایا ای پی ولید هست یا نه