<?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: How can I calculate CIDR Range? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633600#M220069</link>
    <description>&lt;P&gt;This is what worked between&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;suggestions:&lt;/P&gt;&lt;PRE&gt;| eval bitmask = split(Netmask, ".")&lt;BR /&gt;| eval bitmask = 32 - sum(mvmap(bitmask, log(256 - bitmask,2)))&lt;BR /&gt;| eval CIDR = Network_Address . "/" . bitmask&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2023 16:35:28 GMT</pubDate>
    <dc:creator>atebysandwich</dc:creator>
    <dc:date>2023-03-07T16:35:28Z</dc:date>
    <item>
      <title>How can I calculate CIDR Range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633252#M219993</link>
      <description>&lt;P&gt;I have two fields: Network_Address and Netmask. The Network_Address field has the network address of the network as field values and the Netmask field has the network mask as it's value. Here is an example:&lt;BR /&gt;&lt;BR /&gt;Network_Address Netmask&lt;/P&gt;
&lt;P&gt;10.1.1.0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;255.255.255.0&lt;BR /&gt;&lt;BR /&gt;How can I write a search so Splunk tells me the CIDR subnet rage for the two fields? I need the output to be put in a new field named CIDR.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 14:39:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633252#M219993</guid>
      <dc:creator>atebysandwich</dc:creator>
      <dc:date>2023-03-06T14:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate CIDR Range</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633280#M219998</link>
      <description>&lt;P&gt;Not so much a search, but mere calculation using the definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval bitmask = split(Netmask, ".")
| eval bitmask = sum(mvmap(bitmask, log(bitmask + 1, 2)))
| eval CIDR = Network_Address . "/" . bitmask&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your sample data will return&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CIDR&lt;/TD&gt;&lt;TD&gt;Netmask&lt;/TD&gt;&lt;TD&gt;Network_Address&lt;/TD&gt;&lt;TD&gt;bitmask&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10.1.1.0/24&lt;/TD&gt;&lt;TD&gt;255.255.255.0&lt;/TD&gt;&lt;TD&gt;10.1.1.0&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 04 Mar 2023 06:31:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633280#M219998</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-03-04T06:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate CIDR Range</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633288#M220001</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp; is close but it fails for mask which aren't 255 - try flipping it to subtract the number of missing bits from 32&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval bitmask = 32 - sum(mvmap(bitmask, log(256 - bitmask,2)))&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 04 Mar 2023 09:36:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633288#M220001</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-04T09:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate CIDR Range</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633308#M220009</link>
      <description>&lt;P&gt;To simplify netmask validation, I would introduce a lookup, e.g. netmask_lookup:&lt;/P&gt;&lt;PRE&gt;netmask,sigbits&lt;BR /&gt;0.0.0.0,0&lt;BR /&gt;128.0.0.0,1&lt;BR /&gt;192.0.0.0,2&lt;BR /&gt;224.0.0.0,3&lt;BR /&gt;240.0.0.0,4&lt;BR /&gt;248.0.0.0,5&lt;BR /&gt;252.0.0.0,6&lt;BR /&gt;254.0.0.0,7&lt;BR /&gt;255.0.0.0,8&lt;BR /&gt;255.128.0.0,9&lt;BR /&gt;255.192.0.0,10&lt;BR /&gt;255.224.0.0,11&lt;BR /&gt;255.240.0.0,12&lt;BR /&gt;255.248.0.0,13&lt;BR /&gt;255.252.0.0,14&lt;BR /&gt;255.254.0.0,15&lt;BR /&gt;255.255.0.0,16&lt;BR /&gt;255.255.128.0,17&lt;BR /&gt;255.255.192.0,18&lt;BR /&gt;255.255.224.0,19&lt;BR /&gt;255.255.240.0,20&lt;BR /&gt;255.255.248.0,21&lt;BR /&gt;255.255.252.0,22&lt;BR /&gt;255.255.254.0,23&lt;BR /&gt;255.255.255.0,24&lt;BR /&gt;255.255.255.128,25&lt;BR /&gt;255.255.255.192,26&lt;BR /&gt;255.255.255.224,27&lt;BR /&gt;255.255.255.240,28&lt;BR /&gt;255.255.255.248,29&lt;BR /&gt;255.255.255.252,30&lt;BR /&gt;255.255.255.254,31&lt;BR /&gt;255.255.255.255,32&lt;/PRE&gt;&lt;PRE&gt;| lookup netmask_lookup netmask as Netmask output sigbits&lt;/PRE&gt;&lt;P&gt;If sigbits (significant bits) is null, the netmask is invalid, and the network cannot be expressed in CIDR notation.&lt;/P&gt;&lt;P&gt;To mask the address using a valid netmask, let's introduce a macro to perform a bitwise AND between two 8-bit values [1]:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[bitand_8(2)]
args = x, y
definition = sum(1 * (floor($x$ / 1) % 2) * (floor($y$ / 1) % 2), 2 * (floor($x$ / 2) % 2) * (floor($y$ / 2) % 2), 4 * (floor($x$ / 4) % 2) * (floor($y$ / 4) % 2), 8 * (floor($x$ / 8 ) % 2) * (floor($y$ / 8 ) % 2), 16 * (floor($x$ / 16) % 2) * (floor($y$ / 16) % 2), 32 * (floor($x$ / 32) % 2) * (floor($y$ / 32) % 2), 64 * (floor($x$ / 64) % 2) * (floor($y$ / 64) % 2), 128 * (floor($x$ / 128) % 2) * (floor($y$ / 128) % 2))
iseval = 0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Combining all of the above:&lt;/P&gt;&lt;PRE&gt;| makeresults&lt;BR /&gt;| eval Network_Address="10.1.1.0", Netmask="255.255.255.0"&lt;BR /&gt;| lookup netmask_lookup netmask as Netmask output sigbits&lt;BR /&gt;| eval addr_octets=split(Network_Address, "."), netmask_octets=split(Netmask, ".")&lt;BR /&gt;| eval x=tonumber(mvindex(addr_octets, 0, 0)), y=tonumber(mvindex(netmask_octets, 0, 0)), addr0=`bitand_8(x, y)`&lt;BR /&gt;| eval x=tonumber(mvindex(addr_octets, 1, 1)), y=tonumber(mvindex(netmask_octets, 1, 1)), addr1=`bitand_8(x, y)`&lt;BR /&gt;| eval x=tonumber(mvindex(addr_octets, 2, 2)), y=tonumber(mvindex(netmask_octets, 2, 2)), addr2=`bitand_8(x, y)`&lt;BR /&gt;| eval x=tonumber(mvindex(addr_octets, 3, 3)), y=tonumber(mvindex(netmask_octets, 3, 3)), addr3=`bitand_8(x, y)`&lt;BR /&gt;| eval CIDR=addr0.".".addr1.".".addr2.".".addr3."/".sigbits&lt;/PRE&gt;&lt;P&gt;=&amp;gt; 10.1.1.0/24&lt;/P&gt;&lt;P&gt;We can validate with several cases:&lt;/P&gt;&lt;PRE&gt;| eval Network_Address="10.1.1.0", Netmask="255.255.254.0"&lt;/PRE&gt;&lt;P&gt;=&amp;gt; 10.1.0.0/23&lt;/P&gt;&lt;PRE&gt;| eval Network_Address="10.1.1.32", Netmask="0.0.0.0"&lt;/PRE&gt;&lt;P&gt;=&amp;gt; 0.0.0.0/0 (the default route)&lt;/P&gt;&lt;PRE&gt;| eval Network_Address="10.1.1.32", Netmask="255.255.255.255"&lt;/PRE&gt;&lt;P&gt;=&amp;gt; 10.1.1.32/32 (the host route)&lt;/P&gt;&lt;PRE&gt;| eval Network_Address="10.1.1.32", Netmask="255.0.255.0"&lt;/PRE&gt;&lt;P&gt;=&amp;gt; null (invalid netmask)&lt;/P&gt;&lt;P&gt;A simpler solution overall--and one compatible with both IPv4 and IPv6--would offload the work to either a custom command or an external lookup, but the above steps should work for any unprivileged Splunk user.&lt;/P&gt;&lt;P&gt;EDIT: I'm apparently stuck in a pre-9.0 world. You can replace the eval and bitand logic with a single ipmask() eval function [2]. That said, it isn't difficult to perform bitwise operations in core Splunk up to a certain size. For IPv6, you're still better off implementing a custom command or external lookup.&lt;/P&gt;&lt;P&gt;1. &lt;A href="https://en.wikipedia.org/wiki/Bitwise_operation#Mathematical_equivalents" target="_blank" rel="noopener"&gt;https://en.wikipedia.org/wiki/Bitwise_operation#Mathematical_equivalents&lt;/A&gt;&lt;BR /&gt;2.&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.0.4/SearchReference/ConversionFunctions#ipmask.28.26lt.3Bmask.26gt.3B.2C.26lt.3Bip.26gt.3B.29" target="_self"&gt;https://docs.splunk.com/Documentation/Splunk/9.0.4/SearchReference/ConversionFunctions#ipmask.28.26lt.3Bmask.26gt.3B.2C.26lt.3Bip.26gt.3B.29&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Mar 2023 01:48:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633308#M220009</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2023-03-05T01:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate CIDR Range</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633444#M220041</link>
      <description>&lt;P&gt;This seemed work for the most part. The only I issue I see is some of the values in the new CIDR field have&amp;nbsp;&lt;SPAN&gt;.99435343685886 at the end.&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Network address&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Netmask&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CIDR&lt;BR /&gt;10.21.72.1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;255.255.254.0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;10.21.72.0/23.99435343685886&lt;BR /&gt;&lt;BR /&gt;Is there a way to trim the "." and the numbers to the right off it off?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 15:33:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633444#M220041</guid>
      <dc:creator>atebysandwich</dc:creator>
      <dc:date>2023-03-06T15:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate CIDR Range</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633445#M220042</link>
      <description>&lt;P&gt;Haha I didn't see this before I replied back to&amp;nbsp;&lt;A href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901" target="_blank"&gt;@yuanliu&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;post. Your idea did the trick. Thank you both for the help!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 15:38:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633445#M220042</guid>
      <dc:creator>atebysandwich</dc:creator>
      <dc:date>2023-03-06T15:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate CIDR Range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633600#M220069</link>
      <description>&lt;P&gt;This is what worked between&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;suggestions:&lt;/P&gt;&lt;PRE&gt;| eval bitmask = split(Netmask, ".")&lt;BR /&gt;| eval bitmask = 32 - sum(mvmap(bitmask, log(256 - bitmask,2)))&lt;BR /&gt;| eval CIDR = Network_Address . "/" . bitmask&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 16:35:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633600#M220069</guid>
      <dc:creator>atebysandwich</dc:creator>
      <dc:date>2023-03-07T16:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate CIDR Range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633631#M220080</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/253260"&gt;@atebysandwich&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's a tidy solution. Just keep in mind that it assumes Netmask is a valid network mask and Network_Address is a valid network address relative to Netmask. If either assumption is false, the resulting CIDR value is invalid.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 19:51:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/633631#M220080</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2023-03-07T19:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate CIDR Range?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/653102#M225684</link>
      <description>&lt;P&gt;FYI,&lt;/P&gt;&lt;P&gt;I added the following external command lookup to the App below.&lt;/P&gt;&lt;P&gt;Usage:&lt;/P&gt;&lt;PRE&gt;| makeresults&lt;BR /&gt;| eval &lt;SPAN&gt;Network_Address="10.1.1.0", Netmask&lt;/SPAN&gt;="&lt;SPAN&gt;255.255.255.0&lt;/SPAN&gt;"&lt;BR /&gt;&lt;BR /&gt;| eval ip=&lt;SPAN&gt;Network_Address."/".Netmask&lt;/SPAN&gt;&lt;BR /&gt;| lookup local=t ipcalclookup Address as ip OUTPUT Network Prefix&lt;BR /&gt;| eval CIDR=Network."/".Prefix&lt;/PRE&gt;&lt;P&gt;Numeral system macros for Splunk&lt;BR /&gt;&lt;A href="https://splunkbase.splunk.com/app/6595" target="_blank"&gt;https://splunkbase.splunk.com/app/6595&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 18:51:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-calculate-CIDR-Range/m-p/653102#M225684</guid>
      <dc:creator>tfujita_splunk</dc:creator>
      <dc:date>2023-08-03T18:51:23Z</dc:date>
    </item>
  </channel>
</rss>

