Jump to content
UBot Underground

Recommended Posts

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!

  • Like 1
Link to post
Share on other sites

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]))$

:wacko:

 

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+$

:rolleyes:

  • Like 2
Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...