<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Group IP addresses in CIDR format in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24555#M4546</link>
    <description>&lt;P&gt;If there are a limited number of subnets that you want to count, you could do it this way&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval subnet="no match"
| eval subnet=case(cidrmatch("10.10.3.0/24",ip),"10.10.3",
                   cidrmatch("10.10.17.0/24",ip),"10.10.17")
| stats count by subnet
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This assumes that the field containing the ip addresses is named ip. It will work for any CIDR-notated subnet. You can add as many cases as you like to the case function.&lt;/P&gt;

&lt;P&gt;If you want to simply count by the first 3 octets, you could do it this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| rex field=ip "(?&amp;lt;subnet&amp;gt;\d+\.\d+\.\d+)\.\d+"
| stats count by subnet
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 05 Aug 2012 02:16:19 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2012-08-05T02:16:19Z</dc:date>
    <item>
      <title>Group IP addresses in CIDR format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24554#M4545</link>
      <description>&lt;P&gt;I'm trying to group IP address results in CIDR format. Most likely I'll be grouping in /24 ranges. Is there an easy way to do this? Maybe some regex?&lt;/P&gt;

&lt;P&gt;For example, if I have two IP addresses like 10.10.3.5 and 10.10.3.50 I want them to be counted in the 10.10.3.0/24 range, and then see how many IP's are in each range.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2012 18:40:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24554#M4545</guid>
      <dc:creator>jevenson</dc:creator>
      <dc:date>2012-08-02T18:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Group IP addresses in CIDR format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24555#M4546</link>
      <description>&lt;P&gt;If there are a limited number of subnets that you want to count, you could do it this way&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval subnet="no match"
| eval subnet=case(cidrmatch("10.10.3.0/24",ip),"10.10.3",
                   cidrmatch("10.10.17.0/24",ip),"10.10.17")
| stats count by subnet
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This assumes that the field containing the ip addresses is named ip. It will work for any CIDR-notated subnet. You can add as many cases as you like to the case function.&lt;/P&gt;

&lt;P&gt;If you want to simply count by the first 3 octets, you could do it this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| rex field=ip "(?&amp;lt;subnet&amp;gt;\d+\.\d+\.\d+)\.\d+"
| stats count by subnet
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2012 02:16:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24555#M4546</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-08-05T02:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Group IP addresses in CIDR format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24556#M4547</link>
      <description>&lt;P&gt;That second regex search worked great, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2012 16:22:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24556#M4547</guid>
      <dc:creator>jevenson</dc:creator>
      <dc:date>2012-08-08T16:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Group IP addresses in CIDR format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24557#M4548</link>
      <description>&lt;P&gt;I believe there is a minor typo in the first example.  In the second line of the Case clause, the period should be a comma:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
yoursearchhere&lt;BR /&gt;
| eval subnet="no match"&lt;BR /&gt;
| eval subnet=case(cidrmatch("10.10.3.0/24",ip),"10.10.3",&lt;BR /&gt;
                   cidrmatch("10.10.17.0/24",ip),"10.10.17")&lt;BR /&gt;
| stats count by subnet&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2013 18:09:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24557#M4548</guid>
      <dc:creator>anewell</dc:creator>
      <dc:date>2013-01-04T18:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Group IP addresses in CIDR format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24558#M4549</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;REGEX IP ADDRESS
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}

REGEX RFC1918 IP ADDRESS
(192\.168\.)\d{1,3}\.\d{1,3}|(10\.)\d{1,3}\.\d{1,3}\.\d{1,3}|(172\.1[6-9]\.)\d{1,3}\.\d{1,3}|(172\.2[0-9]\.)\d{1,3}\.\d{1,3}|(172\.3[0-1]\.)\d{1,3}\.\d{1,3}

REGEX NON-RFC1918 IP ADDRESS
 \d{1,3}(?&amp;lt;!10|255)\.\d{1,3}\.\d{1,3}\.\d{1,3}
|\d{1,3}\.\d{1,3}(?&amp;lt;!192\.168|255\.255)\.\d{1,3}\.\d{1,3}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2016 18:45:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-IP-addresses-in-CIDR-format/m-p/24558#M4549</guid>
      <dc:creator>jcoates_splunk</dc:creator>
      <dc:date>2016-04-11T18:45:12Z</dc:date>
    </item>
  </channel>
</rss>

