VaultBoss 310 Posted November 8, 2012 Report Share Posted November 8, 2012 I was trying to write some REGEX to filter out the LAN IPs and I found that MightyG has a dedicated tool for that. Thought I'd share, maybe you guys will need such a thing sometimes... http://support.googl...34830&ctx=topic Enjoy! 1 Quote Link to post Share on other sites
VaultBoss 310 Posted November 8, 2012 Author Report Share Posted November 8, 2012 For example, for filtering out the IP Range: 10.0.0.0 ----- 10.255.255.255 ....this tool gives a long and complex (but thoroughly made) string such as: ^10\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$ This would be useful if you are not sure how the IP would be generated, especially if human interaction is implied, because it selects the IPs properly, within the accepted ranges available for each class (0-254) However, if you don't care too much about that (say the IP is correctly formated, being resulted from an automated procedure), you could simplify it a lil' bit as shown on the website I mentioned under the first link, like this string below: ^10\.\d+\.\d+\.\d+$ 2 Quote Link to post Share on other sites
UBotBuddy 331 Posted November 8, 2012 Report Share Posted November 8, 2012 +1 to you. 1 Quote Link to post Share on other sites
VaultBoss 310 Posted November 8, 2012 Author Report Share Posted November 8, 2012 Here is an example code to test the above REGEX in Ubot: ui text box("Check IP for Private/Public Range: ", #var_TEST_IP) set(#var_IP_Type_Public, $nothing, "Global") ui button("Query") { set(#var_IP_Query_Result, $Public_IP_Range(#var_TEST_IP), "Global") } ui stat monitor("Result - IP is Public?", #var_IP_Type_Public) divider divider define $Public_IP_Range(#var_TEST_IP) { set(#var_TEST_IP, $trim(#var_TEST_IP), "Local") set(#var_TMP_IP, $replace regular expression(#var_TEST_IP, "(^10\\.\\d+\\.\\d+\\.\\d+$)", $nothing), "Local") if($comparison($text length(#var_TMP_IP), "<", $text length(#var_TEST_IP))) { then { set(#var_IP_Type_Public, "False", "Global") } else { set(#var_TMP_IP, $replace regular expression(#var_TEST_IP, "(^172\\.(1[6-9]|2[0-9]|3[01])\\.\\d+\\.\\d+$)", $nothing), "Local") if($comparison($text length(#var_TMP_IP), "<", $text length(#var_TEST_IP))) { then { set(#var_IP_Type_Public, "False", "Global") } else { set(#var_TMP_IP, $replace regular expression(#var_TEST_IP, "(^192\\.168\\.\\d+\\.\\d+$)", $nothing), "Local") if($comparison($text length(#var_TMP_IP), "<", $text length(#var_TEST_IP))) { then { set(#var_IP_Type_Public, "False", "Global") } else { set(#var_TMP_IP, $replace regular expression(#var_TEST_IP, "(^169\\.254\\.\\d+\\.\\d+$)", $nothing), "Local") if($comparison($text length(#var_TMP_IP), "<", $text length(#var_TEST_IP))) { then { set(#var_IP_Type_Public, "False", "Global") } else { set(#var_TMP_IP, $replace regular expression(#var_TEST_IP, "(^127\\.0\\.0\\.1$)", $nothing), "Local") if($comparison($text length(#var_TMP_IP), "<", $text length(#var_TEST_IP))) { then { set(#var_IP_Type_Public, "False", "Global") } else { set(#var_IP_Type_Public, "True", "Global") } } } } } } } } } } return(#var_IP_Type_Public) } I just included the other ranges too. Quote Link to post Share on other sites
Legend 181 Posted November 9, 2012 Report Share Posted November 9, 2012 nice... thanks for the share! Quote Link to post Share on other sites
P0s3id0n 90 Posted November 9, 2012 Report Share Posted November 9, 2012 Thanks for the share man just in time for a bot I am working on. Quote Link to post Share on other sites
VaultBoss 310 Posted November 9, 2012 Author Report Share Posted November 9, 2012 You're welcome! If you liked it, hit the LIKE THIS button, man... Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.