<?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 do you match ip address with ip's with CIDR notations in the same lookuptable? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462663#M130433</link>
    <description>&lt;P&gt;Sorry, I was away and thought this question was dead.  When I get the IP list csv, I will try this today. &lt;/P&gt;

&lt;P&gt;First question, We use Excel spreadsheet formatted as a CSV, does that affect the first step?  Can a Excel spreadsheet formatted as a CSV be used instead of formatting a file with commas?&lt;/P&gt;

&lt;P&gt;Second Question, If you have hundreds of CIDR notations, would have every CIDR block out in your SPL (Final SPL)???&lt;/P&gt;

&lt;P&gt;Thanks! =0)&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2020 15:56:47 GMT</pubDate>
    <dc:creator>UMDTERPS</dc:creator>
    <dc:date>2020-02-24T15:56:47Z</dc:date>
    <item>
      <title>How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462657#M130427</link>
      <description>&lt;P&gt;We have a CSV with a field called application and another called IP.  Within the field ip there are ip addresses and some ip addresses with CIDR notation.  We have hundreds of field entries for applications and IP, below is smaller dummy data version of the list:&lt;/P&gt;

&lt;P&gt;Application IP&lt;BR /&gt;
sec_system 192.168.4.0/26&lt;BR /&gt;
sec_system 192.168.1.0/25&lt;BR /&gt;
sec_system 192.168.2.0/24&lt;BR /&gt;
sec_system 192.168.3.0/24&lt;BR /&gt;
internal_system 192.168.2.5&lt;BR /&gt;
internal_system 192.168.3.50&lt;BR /&gt;
internal_system 192.168.4.32&lt;BR /&gt;
internal_system 192.168.1.4&lt;BR /&gt;
win_system 192.168.1.50&lt;BR /&gt;
win_system 192.168.1.3&lt;/P&gt;

&lt;P&gt;Is there a way to match applcations/ips, with applications/ips with CIDR notations?  (I've seen some people say you need to use the tranforms.conf or props.conf file, I can't use that file because I don't have access to it)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:03:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462657#M130427</guid>
      <dc:creator>UMDTERPS</dc:creator>
      <dc:date>2020-09-30T04:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462658#M130428</link>
      <description>&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.1/Knowledge/Usefieldlookupstoaddinformationtoyourevents"&gt;lookup&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Do you create &lt;CODE&gt;lookup&lt;/CODE&gt; with matchtype &lt;EM&gt;CIDR&lt;/EM&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 22:04:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462658#M130428</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-02-05T22:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462659#M130429</link>
      <description>&lt;P&gt;It's a little cumbersome, but this is entirely doable &lt;EM&gt;without&lt;/EM&gt; modifying system files like transforms.conf or props.conf.  I'll also add the disclaimer that performance might be awful if your lookup CSV file really needs that many values and you have a lot of results in your search to lookup.&lt;/P&gt;

&lt;H2&gt;There are a lot of steps below, but don't let them intimidate you.  Follow me...&lt;/H2&gt;

&lt;P&gt;&lt;STRONG&gt;First&lt;/STRONG&gt;, let's get your CSV in proper shape or it's a non-starter.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Move your IP column to be the first, not second column.&lt;/LI&gt;
&lt;LI&gt;Make sure you have a comma between the first and second column.  &lt;EM&gt;It is a CSV, after all, right?&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Make sure all entries in the IP column are in CIDR format.  That means changing the specific IP addresses you have like 192.168.2.5 to 192.168.2.5/32 instead.&lt;/LI&gt;
&lt;LI&gt;Sort your list from most-specific to least-specific.  Sorting as decreasing subnet mask length, and you should be fine.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Based on your example, here's what I used as my lookup file after making these changes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;IP,Application
192.168.1.3/32,win_system
192.168.1.4/32,internal_system
192.168.1.50/32,win_system
192.168.1.0/24,sec_system
192.168.2.5/32,internal_system 
192.168.2.0/24,sec_system
192.168.3.50/32,internal_system
192.168.3.0/25,sec_system
192.168.4.32/32,internal_system
192.168.4.0/26,sec_system
10.0.0.0/8,desktops
172.16.0.0/12,servers
0.0.0.0/0,catchall
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I took the liberty of adding some additional ranges to represent stuff that would fall outside the ranges in your CSV file.  Presumably, you don't have your entire network mapped out in this CSV file.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;  Also, notice I didn't exactly follow my own advice and sort by decreasing subnet mask, but you'll notice the entries &lt;EM&gt;are&lt;/EM&gt; that way &lt;EM&gt;by subnet&lt;/EM&gt; for easy human readability.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;Next&lt;/STRONG&gt;, with the CSV file issues sorted, I had to simulate results from some searches you'd run.  I used the following SPL to generate some random IP addresses in my results.  You don't need to do this if you're getting IP addresses in the real searches you're using in your environment.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=30
| eval raw=split("192.168.X.Y,192.168.X.Y,192.168.X.Y,192.168.X.Y,192.168.X.Y,192.168.X.Y,10.X.Y.Z,172.W.X.Y",",")
| eval raw_ip=mvindex(raw,random()%8)
| eval rnd1 = random()%5
| eval rnd2 = random()%60
| eval rnd3 = random()%256
| eval rnd4 = 16 + random()%16
| eval IP=replace(replace(replace(replace(raw_ip,"W",rnd4),"Z",rnd3),"Y",rnd2),"X",rnd1)
| fields _time,IP
`comment("Mocked-up sample data with credit to to4kawa")`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You should get 30 IP addresses in the private ranges from this.  &lt;STRONG&gt;Don't fret if you don't understand this search&lt;/STRONG&gt; -- remember this just replicates your search results, i.e., it has nothing to do with the lookup itself.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;OK, we have some random data, we have good lookup data.  &lt;STRONG&gt;Now it's time to tackle setting up the lookup within Splunk.&lt;/STRONG&gt;  No elevated rights necessary!&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Logged into Splunk, click &lt;STRONG&gt;Settings&lt;/STRONG&gt; --&amp;gt; &lt;STRONG&gt;Lookups&lt;/STRONG&gt; in the upper right.&lt;/LI&gt;
&lt;LI&gt;Click &lt;STRONG&gt;Add new&lt;/STRONG&gt; next to &lt;STRONG&gt;Lookup table files&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Change the &lt;STRONG&gt;Destination app&lt;/STRONG&gt; drop-down menu to match whatever app you're using in your environment for this search.  This might be irrelevant for you.&lt;/LI&gt;
&lt;LI&gt;Click the &lt;STRONG&gt;Browse&lt;/STRONG&gt; button and select the CSV file &lt;EM&gt;after you've made the required corrections I outlined above&lt;/EM&gt;.&lt;/LI&gt;
&lt;LI&gt;I recommend making the &lt;STRONG&gt;Destination filename&lt;/STRONG&gt; the same as the name of your CSV for the sake of simplicity.  Whatever you use here arbitrary, but you'll refer to it by this name in a later step.  I'll use the name &lt;STRONG&gt;priv_ip_lookup.csv&lt;/STRONG&gt; for this explanation.&lt;/LI&gt;
&lt;LI&gt;Click &lt;STRONG&gt;Save&lt;/STRONG&gt; to save your new lookup.  You should be taken back to the list of all lookup files registered in the system, and your new file will be listed here unless you ran into an error.&lt;/LI&gt;
&lt;LI&gt;Go back to &lt;STRONG&gt;Settings&lt;/STRONG&gt; --&amp;gt; &lt;STRONG&gt;Lookups&lt;/STRONG&gt;.  This time around, click &lt;STRONG&gt;Add new&lt;/STRONG&gt; next to &lt;STRONG&gt;Lookup definitions&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;As before, change the &lt;STRONG&gt;Destination app&lt;/STRONG&gt; drop-down menu to match whatever app you're using in your environment for this search.  This might be irrelevant for you.  If it was irrelevant before, it is here, too.&lt;/LI&gt;
&lt;LI&gt;For &lt;STRONG&gt;Name&lt;/STRONG&gt;, come up with a name for this lookup definition.  It's arbitrary, but you'll refer to the lookup definition using this name in your SPL.  I'll use &lt;STRONG&gt;priv_ip_lookup&lt;/STRONG&gt; for this example.&lt;/LI&gt;
&lt;LI&gt;Don't change the &lt;STRONG&gt;Type&lt;/STRONG&gt; -- keep it at &lt;STRONG&gt;File-based&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Find your lookup file in the &lt;STRONG&gt;Lookup file&lt;/STRONG&gt; drop-down menu.  For this example, I would select &lt;STRONG&gt;priv_ip_lookup.csv&lt;/STRONG&gt; since that's what I uploaded in step 5.&lt;/LI&gt;
&lt;LI&gt;Now the really important part...check &lt;STRONG&gt;Advanced options&lt;/STRONG&gt; to expose additional options.&lt;/LI&gt;
&lt;LI&gt;Set &lt;STRONG&gt;Maximum matches&lt;/STRONG&gt; to &lt;STRONG&gt;1&lt;/STRONG&gt; unless you want to deal with multi-value fields after your lookup.  If you've sorted your data properly (remember?), you will get the expected result and only 1 result after your lookup.&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Match type&lt;/STRONG&gt; field, type this:  &lt;STRONG&gt;CIDR(IP)&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;Click &lt;STRONG&gt;Save&lt;/STRONG&gt; to save your new lookup definition.  You should be taken back to the list of all lookup definitions registered in the system, and your new definition will be listed here unless you ran into an error.&lt;/LI&gt;
&lt;/OL&gt;

&lt;HR /&gt;

&lt;P&gt;Almost there!  All the setup is done.  Now it's just a matter of implementing the all-important lookup command in your SPL.&lt;/P&gt;

&lt;P&gt;Add this line to the end of whatever your search is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| lookup priv_ip_lookup IP OUTPUT Application
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Anticlimactic, isn't it?&lt;BR /&gt;
The lookup command uses the &lt;STRONG&gt;priv_ip_lookup&lt;/STRONG&gt; definition you created, which is configured to lookup by CIDR match of the IP field and output the Application column, adding that column to your search results.&lt;/P&gt;

&lt;P&gt;Here's my final SPL while developing this answer:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=30
| eval raw=split("192.168.X.Y,192.168.X.Y,192.168.X.Y,192.168.X.Y,192.168.X.Y,192.168.X.Y,10.X.Y.Z,172.W.X.Y",",")
| eval raw_ip=mvindex(raw,random()%8)
| eval rnd1 = random()%5
| eval rnd2 = random()%60
| eval rnd3 = random()%256
| eval rnd4 = 16 + random()%16
| eval IP=replace(replace(replace(replace(raw_ip,"W",rnd4),"Z",rnd3),"Y",rnd2),"X",rnd1)
| fields _time,IP
`comment("Mocked-up sample data with credit to to4kawa")`
| lookup priv_ip_lookup IP OUTPUT Application
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My sample output looks like the following, but your results will vary due to the random() calls to generate the IPs in my results.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time        IP      Application    
2020-02-10 13:22:27     192.168.4.5     sec_system
2020-02-10 13:22:27     192.168.3.55    sec_system
2020-02-10 13:22:27     192.168.2.54    sec_system
2020-02-10 13:22:27     192.168.3.36    sec_system
2020-02-10 13:22:27     192.168.2.5     internal_system
2020-02-10 13:22:27     192.168.3.20    sec_system
2020-02-10 13:22:27     192.168.4.18    sec_system
2020-02-10 13:22:27     192.168.4.9     sec_system
2020-02-10 13:22:27     192.168.4.8     sec_system 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note the &lt;EM&gt;internal_system&lt;/EM&gt; match on the specific 192.168.2.5 address in your example.  This works ONLY after you change that reference in your lookup file to 192.168.2.5/32, otherwise you'll get &lt;EM&gt;sec_system&lt;/EM&gt; instead.&lt;/P&gt;

&lt;P&gt;IP lookups are messy, but they're great once you get them configured properly.&lt;/P&gt;

&lt;P&gt;Hope that helps!&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:09:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462659#M130429</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-09-30T04:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462660#M130430</link>
      <description>&lt;P&gt;@UMDTERPS did this solve your problem?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 23:32:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462660#M130430</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-02-11T23:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462661#M130431</link>
      <description>&lt;P&gt;@UMDTERPS ?&lt;BR /&gt;
Were you able to use this to complete the work you wanted to do or do you need additional help?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 15:06:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462661#M130431</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-02-14T15:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462662#M130432</link>
      <description>&lt;P&gt;Did the answer I detailed below provide you with the information you needed?&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 14:20:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462662#M130432</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-02-19T14:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462663#M130433</link>
      <description>&lt;P&gt;Sorry, I was away and thought this question was dead.  When I get the IP list csv, I will try this today. &lt;/P&gt;

&lt;P&gt;First question, We use Excel spreadsheet formatted as a CSV, does that affect the first step?  Can a Excel spreadsheet formatted as a CSV be used instead of formatting a file with commas?&lt;/P&gt;

&lt;P&gt;Second Question, If you have hundreds of CIDR notations, would have every CIDR block out in your SPL (Final SPL)???&lt;/P&gt;

&lt;P&gt;Thanks! =0)&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 15:56:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462663#M130433</guid>
      <dc:creator>UMDTERPS</dc:creator>
      <dc:date>2020-02-24T15:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462664#M130434</link>
      <description>&lt;P&gt;I thought this question was dead, too!&lt;/P&gt;

&lt;P&gt;1) When Excel saves files to CSV, there will be a comma between the fields.  I stated what I did only because there were spaces delimiting your fields in your sample file.&lt;BR /&gt;
2) No, sorry, I think you misunderstood my "final SPL".  You would not need to list out all of your CIDR notations in the SPL, only in the CSV.  Once you get your CSV in good shape and the lookup configured in Splunk, line 11 ( | lookup priv_ip_lookup IP OUTPUT Application) is the only line you need to worry about in your SPL.&lt;/P&gt;

&lt;P&gt;I'll start watching this question a little more closely!&lt;BR /&gt;
rmmiller&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:53:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/462664#M130434</guid>
      <dc:creator>rmmiller</dc:creator>
      <dc:date>2020-09-30T04:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do you match ip address with ip's with CIDR notations in the same lookuptable?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/516359#M145090</link>
      <description>&lt;P&gt;My apologies for taking a while to get back to you.&amp;nbsp; I wasn't able to get the data back to test this on that data, but I did some testing and it appears this works.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 19:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-match-ip-address-with-ip-s-with-CIDR-notations-in-the/m-p/516359#M145090</guid>
      <dc:creator>UMDTERPS</dc:creator>
      <dc:date>2020-08-26T19:09:27Z</dc:date>
    </item>
  </channel>
</rss>

