Jump to content

Looking for a relatively simple method to create regex patterns to detect a number range


Go to solution Solved by Morthawt,

Recommended Posts

Posted

I ran your script but I see no regex being pumped out of it.

You are correct. My script of post #39 does not use a regex to check if an Ip address is within a CIDR address.

The line,

"Return ($IpNum >= $LowIp And ($IpNum <= $UpIp)) ? 1 : 0"

is used to check if an Ip address is within a CIDR address.

I originally used the following regex method. But I thought the bit functions method of post #39 was easier and simpler. 

; From Post #13
; "^64\.237\.(3[2-9]|[45][0-9]|6[0-3])\.[0-9]+$"
;   64.237  .(32-39 |40-59    |60-63)  .(0-infinity)

; Create RE Pattern to match IPs in the range of 192.168.12.1 - 192.168.15.254
Local $REPattern = "192\.168\." & _RERange(12, 15) & "\." & _RERange(1, 254)
ConsoleWrite($REPattern & @LF)

$sChckIP1 = "192.168.12.1"
ConsoleWrite(StringRegExp($sChckIP1, $REPattern) & @LF) ; Returns "1" for True (ChckIp is within range of Ip's).

$sChckIP2 = "192.168.12.0"
ConsoleWrite(StringRegExp($sChckIP2, $REPattern) & @LF) ; Returns "0" for Fakse (ChckIp is not within range of Ip's).


Func _RERange($iLowerLimit, $iUpperLimit)
    Local $Ret = "("
    For $i = $iLowerLimit To $iUpperLimit
        $Ret &= $i & "|"
    Next
    Return StringTrimRight($Ret, 1) & ")"
EndFunc   ;==>_RERange
  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

 

You are correct. My script of post #39 does not use a regex to check if an Ip address is within a CIDR address.

The line,

"Return ($IpNum >= $LowIp And ($IpNum <= $UpIp)) ? 1 : 0"

is used to check if an Ip address is within a CIDR address.

I originally used the following regex method. But I thought the bit functions method of post #39 was easier and simpler. 

; From Post #13
; "^64\.237\.(3[2-9]|[45][0-9]|6[0-3])\.[0-9]+$"
;   64.237  .(32-39 |40-59    |60-63)  .(0-infinity)

; Create RE Pattern to match IPs in the range of 192.168.12.1 - 192.168.15.254
Local $REPattern = "192\.168\." & _RERange(12, 15) & "\." & _RERange(1, 254)
ConsoleWrite($REPattern & @LF)

$sChckIP1 = "192.168.12.1"
ConsoleWrite(StringRegExp($sChckIP1, $REPattern) & @LF) ; Returns "1" for True (ChckIp is within range of Ip's).

$sChckIP2 = "192.168.12.0"
ConsoleWrite(StringRegExp($sChckIP2, $REPattern) & @LF) ; Returns "0" for Fakse (ChckIp is not within range of Ip's).


Func _RERange($iLowerLimit, $iUpperLimit)
    Local $Ret = "("
    For $i = $iLowerLimit To $iUpperLimit
        $Ret &= $i & "|"
    Next
    Return StringTrimRight($Ret, 1) & ")"
EndFunc   ;==>_RERange

I am not sure if you realise what this program is for. It is to generate regex patterns for use in another software product called TeamSpeak that can take regex IP bans. I am not doing any checks, tests or anything in AutoIt. I am using AutoIt to generate regex patterns, thats it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...