<?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 to edit my search to match an IP from Data to a Subnet IP in a lookup file? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290696#M87835</link>
    <description>&lt;P&gt;You would need to setup a lookup definition (needs conf file access) on your search head to enable CIDR match. Have a look at this post for detailed instructions:- &lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html"&gt;https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You can skip the step of automatic lookup.&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2017 16:48:30 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-05-12T16:48:30Z</dc:date>
    <item>
      <title>How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290695#M87834</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| set union [search index=*_place_holder sourcetype=placeholder | fields src_ip | where src_ip!="N/A"| rename src_ip as c_ip |fields c_ip ] [searchindex=*_place_holder sourcetype=placeholder | fields dest_ip |where dest_ip!="N/A"|rename dest_ip as c_ip|fields c_ip ] | table c_ip |dedup c_ip|lookup lookupfile.csv SUBNET as c_ip OUTPUT SUBNET_NAME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That's the search I have so far. It does combine the two fields src_ip and dest_ip in to c_ip successfully. But now I need to find a way to compare c_ip with the SUBNET field in lookupfile.csv. Matching the first 3 octets would be the best way for me, but i'm not sure how to go about this. Also, how would I modify the search so the results show Matches and Non-Matches a two separate fields?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:03:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290695#M87834</guid>
      <dc:creator>sai21</dc:creator>
      <dc:date>2020-09-29T14:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290696#M87835</link>
      <description>&lt;P&gt;You would need to setup a lookup definition (needs conf file access) on your search head to enable CIDR match. Have a look at this post for detailed instructions:- &lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html"&gt;https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You can skip the step of automatic lookup.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 16:48:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290696#M87835</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-05-12T16:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290697#M87836</link>
      <description>&lt;P&gt;the SUBNET field in my lookup file doesn't have the subnet mask next to the next ip address like it is shown in that example. Can I still use CIDR match?&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 16:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290697#M87836</guid>
      <dc:creator>sai21</dc:creator>
      <dc:date>2017-05-15T16:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290698#M87837</link>
      <description>&lt;P&gt;Can we have some sample values from IP address in your events and subnet values from your lookup?&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 16:21:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290698#M87837</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-05-15T16:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290699#M87838</link>
      <description>&lt;P&gt;c_ip example: 198.241.211.29&lt;BR /&gt;
SUBNET value example: 198.241.211.0&lt;/P&gt;

&lt;P&gt;another pair: &lt;/P&gt;

&lt;P&gt;c_ip: 10.121.3.248&lt;BR /&gt;&lt;BR /&gt;
SUBNET: 10.121.3.0&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2017 17:11:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290699#M87838</guid>
      <dc:creator>sai21</dc:creator>
      <dc:date>2017-05-15T17:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290700#M87839</link>
      <description>&lt;P&gt;Any ideas? I put some samples of how the data looks&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 14:01:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290700#M87839</guid>
      <dc:creator>sai21</dc:creator>
      <dc:date>2017-05-17T14:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290701#M87840</link>
      <description>&lt;P&gt;simple enough - if you only want to match the first 3 octets, then create your lookup table with only the first three octets as the key, and only use the first three octets to look it up.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;table  mylookup.csv

subnet_key  result_ip
10.121.3      10.121.3.0

incoming c_ip: 10.121.3.248 

| rex field=c_ip "^(?&amp;lt;subnet_key1&amp;gt;\d+\.\d+\.\d+)\.\d*"
| lookup mylookup.csv subnet_key as subnet_key1 OUTPUT  result_ip as result_ip1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Run-anywhere example.  First run this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults 
 | eval subnet_key="10.121.3" 
 | eval result_ip="10.121.3.0" 
 | table subnet_key result_ip
 | outputlookup mylookup.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... with this result table...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;subnet_key   result_ip 
10.121.3     10.121.3.0  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...then run this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval c_ip="10.121.3.248" 
| rex field=c_ip "^(?&amp;lt;subnet_key1&amp;gt;\d+\.\d+\.\d+)\.\d*"
| lookup mylookup.csv subnet_key as subnet_key1 OUTPUT  result_ip as result_ip1
| table c_ip subnet_key1 result_ip1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... with this result output...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;c_ip          subnet_key1  result_ip1 
10.121.3.248  10.121.3     10.121.3.0  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2017 16:05:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290701#M87840</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-17T16:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290702#M87841</link>
      <description>&lt;P&gt;The problem is, I can't modify the lookup file SUBNET field to only have the first 3 octets. Can i use a rex field to get the first 3 octets of SUBNET to use as a new field? If so, where would this be in the query? After the lookup command?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| set union [search index=*_place_holder sourcetype=placeholder | fields src_ip | where src_ip!="N/A"| rename src_ip as c_ip |fields c_ip ] [search index=*_place_holder sourcetype=placeholder | fields dest_ip |where dest_ip!="N/A"|rename dest_ip as c_ip|fields c_ip ] | table c_ip |dedup c_ip|rex field=c_ip "^(?&amp;lt;subnet_key1&amp;gt;\d+\.\d+\.\d+)\.\d*"|lookup lookupfile.csv SUBNET as subnet_key1 OUTPUT  result_ip as result_ip1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;that gives me this output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;c_ip                          result_ip     subnet_key1
10.43.117.129                               10.43.117
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2017 18:34:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290702#M87841</guid>
      <dc:creator>sai21</dc:creator>
      <dc:date>2017-05-17T18:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to match an IP from Data to a Subnet IP in a lookup file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290703#M87842</link>
      <description>&lt;P&gt;This can be a workaround, but won't be efficient cause usage of join.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| set union [search index=*_place_holder sourcetype=placeholder | fields src_ip | where src_ip!="N/A"| rename src_ip as c_ip |fields c_ip ] [searchindex=*_place_holder sourcetype=placeholder | fields dest_ip |where dest_ip!="N/A"|rename dest_ip as c_ip|fields c_ip ] | table c_ip |dedup c_ip|join c_ip [|inputlookup lookupfile.csv | eval c_ip=replace(SUBNET,"(\d+\.\d+\.\d+)\.\d+","\1") | table c_ip SUBNET_NAME ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2017 18:39:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-match-an-IP-from-Data-to-a-Subnet-IP-in/m-p/290703#M87842</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-05-17T18:39:14Z</dc:date>
    </item>
  </channel>
</rss>

