Archive: IP Address verification doesnt work


IP Address verification doesnt work
Hello all

I modified the ValidationIP function in such way that to check for the given address is within our IP address range. But the code seems to be not working and always showing the same result.

Could you please help me out with verification of the validationIP.nsh file.

Here is the code:

!include LogicLib.nsh
!include WordFunc.nsh
!insertmacro WordFind
!insertmacro StrFilter
!insertmacro WordFind2X


Function ValidateIP

Exch $0
Push $1
Push $2

${StrFilter} $0 1 "." "" $1
${If} $0 != $1
# invalid charcaters used
# example: a127.0.0.1
Goto error
${EndIf}

${WordFind} $0 . "#" $1
${If} $1 != 4
# wrong number of numbers
# example: 127.0.0.
Goto error
${EndIf}

${WordFind} $0 . "*" $1
${If} $1 != 3
# wrong number of dots
# example: 127.0.0.1.
Goto error
${EndIf}
# Extracts the first part of Ip address 192.168.xx.x (192) and checks for the number.
${WordFind} $0 "." "+1{" $1
${If} $1 < 255
${OrIf} $1 > 0

IntCmp $1 192 +3

${Else}
# invalid number
# example: 500.0.0.1
Goto error
${EndIf}
# Extracts the Second part of Ip address 192.168.xx.x (18) and checks for the number.

${WordFind2X} $0 "." "." "+2" $1
${If} $1 < 255
${OrIf} $1 > 0

IntCmp $1 18 +3

${Else}
# invalid number
# example: 500.0.0.1
Goto error
${EndIf}

# Extracts the third part of Ip address 192.168.xx.x (xx) and checks for the number.
${WordFind2X} $0 "." "." "+3" $1
${If} $1 > 255
${OrIf} $1 < 0
# invalid number
# example: 500.0.0.1
Goto error
${EndIf}

# Extracts the fourth part of Ip address 192.168.xx.x (x) and checks for the number.
${WordFind2X} $0 "." "." "+4" $1
${If} $1 > 255
${OrIf} $1 < 0
# invalid number
# example: 500.0.0.1
Goto error
${EndIf}


Pop $2
Pop $1
Pop $0

ClearErrors

Return

error:

Pop $2
Pop $1
Pop $0

SetErrors

FunctionEnd



I called this function for verfication through .nsi file where its invoking always "IP is OK"

Please help me out.

Thanks.

IntCmp $1 18 +3

you can't use relative jumps inside ${If} etc. logic statements.

use absolute jumps instead (with labels)

or better, abandon the IntCmp/StrCmp things and use ${If} etc. more straighforward!


IP address verfication is working
Hello

i made a silly mistakes in the code and rectified all those and shame on myself:o

thanks.