Use Perl to Match IP to Subnets

In the case that you have many IP addresses in your logs and don’t know what networks they belong to, you can easily map them using Perl.

  • You must have a database of networks to match against
  • use NetAddr::IP module to help you do the heavy lifting
  • Create a subroutine to convert between dotted dash format and decimal (for sorting)
  • Then loop over all of your ips and see where they fit!

Custom Perl Programming can solve tedious work like this in seconds without the risk of errors. This particular snippet was written to parse millions of IP addresses against a few thousand known networks. What will you use our Perl script that matches IP to subnets for?

Here is the script that uses Perl to match IP to subnets:

2 thoughts on “Use Perl to Match IP to Subnets

  • October 9, 2018 at 3:42 pm

    I appreciate that you shared your code.

    • December 31, 2018 at 5:17 pm

      Thank you Johnathan.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.