'private IP'에 해당되는 글 1건

  1. 2010.07.29 Search the public IP adresses only

Search the public IP adresses only

|
You want to make a keyword or search expression to find an any IP address except private IP adresses.

GREP will help you in this case.

Since private IP addresses belong to the ranges:

10.0.0.0-10.255.255.255
172.16.0.0-172.31.255.255
192.168.0.0-192.168.255.255

There would have to be a ton of conditional statements when parsing a string to eliminate just these ranges. 

The best I could come up with gets everything except the 10, 172 and 192 starting octets.

([1-9]|([11-171]|([173-191]|[193-255])))\.([1-2]?[0-9]?[0-9]\.){2}[1-2]?[0-9]?[0-9]

172\.([1-16]|[32-255])\.[1-2]?[0-9]?[0-9]\.[1-2]?[0-9]?[0-9]

This will grab everything in the 172 octet that was missed in the first search expression.

192\.([1-167]|[169-255])\.[1-2]?[0-9]?[0-9]\.[1-2]?[0-9]?[0-9]

This will grab everything in the 192 octet that was missed in the first expression.

To help you learn what this says:

(a|b) = Either "a" or "b". The "|" means OR.

((num0)|(num1)|((num2)|(num3))) = These can be stacked. A number will be matched if it meets any one of the three number conditions. 

[1-9] = (num0) = means any numbers in the range of 1-9
[11-171] = (num1) = means any number in the range of 1-171
[173-191] = (num2) = means any number in the range of 173-191
[193-255] = (num3) = means any number in the range of 193-255

So this means any octet starting at 1 but not including 172 or 192 will be hit.

\. = the next character must be a "." (period)

([1-2]?[0-9]?[0-9]\.) = A "?" means the expression to the left is optional. 

So this expression will match a number in the range of 0-299 followed by a period

(we know it only needs to cover 1-255 but this will match any of those numbers)

{2} = The previous expression has to be found twice, i.e. 0-299.0-299.

[1-2]?[0-9]?[0-9] = The final number has to be in the range 0-299

* [0-9] can be replaced by # or \d
And
prev | 1 | next