How to select all IP addresses in Sublime Text

Regex to select all IP addresses in Sublime Text

Contents

Sometimes, to increase the security of your server or VPS (Virtual Private Server), you need to create a block list for certain IP addresses.

Let’s say you found such a source of IP addresses to block. Say, from a certain country or region. Now you need to merge them all into one list for blocking on the server. How do you find and select all the IP addresses in the text?

  • Open the file containing the IP addresses in SublimeText and go to Find - Replace....

  • Make sure you have the RegEx selector enabled - it looks like a .* sign next to the search field.

  • For IP addresses that look like this: 99.7.83.38 enter the following regex: \b(\d{1,3}\.){3}\d{1,3}\b.

  • For IP addresses that look like this: 99.61.204.91/32 enter the following regex: \b(\d{1,3}\.){3}\d{1,3}\/\d+\b

  • Then click the Find All button (on the right) and copy them into a single blacklist of IP addresses.

  • After that you can leave only unique values. To do this, open the menu Edit - Permute Lines - Unique. Depending on the length of the list it may take a few seconds or minutes.

  • Save the file and use it for your needs.

Come back to read more often for new tips on how to work quickly and efficiently.

PS. This answer about choosing IP addresses is also good.