How to find if an IP address falls in a range specified using a pattern? - ASP.NET -
if have ip address: 192.100.100.2 , need ensure falls within range specified using wildcard patterns.
the patterns can either:
1. 192. *. *. * 2. *. *. *. * 3. 192.1**. *.2
so essentially, asterisk or 3 asterisks specify valid range. there built in in asp.net can use validate ip address or more of custom validation?
as @atomerz said, convert patterns regular expressions:
''//patterns search dim patterns() string = {"192.*.*.*", "*.*.*.*", "192.1**.*.2"} ''//test ip dim testip = "192.100.100.2" ''//loop through each pattern each p in patterns ''//swap 2 asterisk 2 regex digits (\d\d) , 1 asterisk 1 or more digits. escape period trace.writeline(system.text.regularexpressions.regex.ismatch(testip, p.replace("**", "\d\d").replace("*", "\d+").replace(".", "\."))) next
Comments
Post a Comment