IP control
Does anybody have handy IP control which allows to input only valid IP thus making unnecessary complicated checking?
6 posts
The code does not verify a lot of things like that first section is not 0 but suits for most of situations.
Var IpToCheck
Var IpSectionsCount ; every IP consists of 4 sections
Function CheckIsIpValid
Pop $IpToCheck ; trimmed ip
StrCpy $IpSectionsCount 0
${Do}
Push "." ; divider char
Push $IpToCheck
Call SplitFirstStrPart
Pop $1 ; first IP number
Pop $IpToCheck ; the rest of IP string
Push $1 ; verify if numeric
Call IsNumeric
Pop $0
${if} $0 == 0
goto invalid_ip
${else}
${if} $1 < 0
goto invalid_ip
${endif}
${if} $1 > 255
goto invalid_ip
${endif}
${endif}
IntOp $IpSectionsCount $IpSectionsCount + 1
${LoopUntil} $IpToCheck == ""
${if} $IpSectionsCount == 4
Push 1 ; OK, valid IP
${else}
goto invalid_ip
${endif}
Return
invalid_ip:
Push 0 ; Invalid IP
FunctionEnd