Skip to content
⌘ NSIS Forum Archive

IP control

6 posts

Yurik#

IP control

Does anybody have handy IP control which allows to input only valid IP thus making unnecessary complicated checking?
Yurik#
It's a pity that nobody answered. Here is my solution which is just silly checking of a string entered in text box:


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
The code does not verify a lot of things like that first section is not 0 but suits for most of situations.
SplitFirstStrPart -

IsNumeric - http://forums.winamp.com/showthread....ring+is+number
Comperio#
InstallOptionsEX has custom page function for IP addresses. It may work for what you need.

Also, Check IP might be an alternative way to check an IP address.
Yurik#
I've tried CheckIP but it is a bit obscure. It seems that is really checks ip (not just ip number correctness) which is sometimes not needed in an installer.
I will try to see InstallOptionsEx, thanks!
JoeMcC00L#
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


Heh, I thought I was the only one looking for this. I haven't found a workable solution yet. For some reason, InstallOptionsEx has some trouble displaying my InstallOptions pages. (And it doesn't help that the project is abandoned 🙁).

Anyway, I know I posted a bit later than you but I figured the screenshot in mine might help.

Joe
deguix#
Well... I recommend using the function to verify the IP. The control is buggy, just like everything else in the plug-in.