<?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 I find all unique IP addresses in a file? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14214#M1472</link>
    <description>&lt;P&gt;&lt;CODE&gt;eval&lt;/CODE&gt; &lt;CODE&gt;split&lt;/CODE&gt; is new in 4.1, but older versions can use &lt;CODE&gt;makemv&lt;/CODE&gt; to do the same thing.&lt;/P&gt;</description>
    <pubDate>Wed, 26 May 2010 20:35:55 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2010-05-26T20:35:55Z</dc:date>
    <item>
      <title>How do I find all unique IP addresses in a file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14208#M1466</link>
      <description>&lt;P&gt;If I have data that looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(date) srcip=x.x.x.x dstip=y.y.y.y
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I create a single list of all unique IPs regardless of src/dst?&lt;/P&gt;

&lt;P&gt;I imagine this is some sort of funky stats option...&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 22:27:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14208#M1466</guid>
      <dc:creator>bfaber</dc:creator>
      <dc:date>2010-05-25T22:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find all unique IP addresses in a file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14209#M1467</link>
      <description>&lt;P&gt;You could use a search like this:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
  &lt;P&gt;&lt;CODE&gt;source=my_file | rex max_match=100 "\b(?&amp;lt;ip&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b" | stats values(ip) as ip_list&lt;/CODE&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;That should make a multivalued field called &lt;CODE&gt;ip&lt;/CODE&gt; and populates it with any IP-like values found in the event's raw text.  Then the &lt;CODE&gt;stats&lt;/CODE&gt; command will build a single list of unique values of your ip addresses.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Regex hint:&lt;/EM&gt;  Note that the regex "&lt;CODE&gt;\b&lt;/CODE&gt;" is for boundary matching.  It should match an "&lt;CODE&gt;=&lt;/CODE&gt;" or a space before the IP address, and should also allow for a comma after the IP address; all of which may be common values before/after an ip address.  Also, &lt;CODE&gt;\b&lt;/CODE&gt; also matches the very beginning and very end of an event.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;If you already have your &lt;CODE&gt;ip&lt;/CODE&gt; address fields defined and you have different names for different sourcetype (which tends to happen), you can use the &lt;CODE&gt;eval&lt;/CODE&gt; command to combine them.  (You can also setup a field alias, but sometimes that may not always be preferable.)  For example, say you had fields called &lt;CODE&gt;dst&lt;/CODE&gt;, &lt;CODE&gt;DST&lt;/CODE&gt;, &lt;CODE&gt;dest&lt;/CODE&gt;, and &lt;CODE&gt;dstip&lt;/CODE&gt; , you could pull them into a single field using a command like so:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
  &lt;P&gt;&lt;CODE&gt;| eval new_destip=coalesce(dst,DST,dest,dstip)&lt;/CODE&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;So if you want to look at both a source ip address and a dest ip address and then combine them, you could use the same approach for both fields, then use some ugly tricks to convert that into a single multi-value field, and then you can use the &lt;CODE&gt;stats&lt;/CODE&gt; command to get your list of unique IPs....&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
  &lt;P&gt;&lt;CODE&gt;| eval d=coalesce(dst,DST,dest,dstip,"") | eval s=coalesce(src,SRC,srcip,"") | eval ips=s.";".d | eval ips=split(ips, ";") | stats values(ips) as ip&lt;/CODE&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;EM&gt;Note:  the eval &lt;CODE&gt;split()&lt;/CODE&gt; function is new in Splunk 4.1.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 23:09:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14209#M1467</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-25T23:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find all unique IP addresses in a file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14210#M1468</link>
      <description>&lt;P&gt;I think an easy way to do it is to do a field extraction of the ip addresses, and then do a &lt;/P&gt;

&lt;P&gt;"... | dedup ip | fields ip | fields - _*"&lt;/P&gt;

&lt;P&gt;to remove dupes and get only the ip address field.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 23:12:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14210#M1468</guid>
      <dc:creator>erydberg</dc:creator>
      <dc:date>2010-05-25T23:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find all unique IP addresses in a file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14211#M1469</link>
      <description>&lt;P&gt;Keep in mind that using &lt;CODE&gt;dedup&lt;/CODE&gt; will probably not work as you would expect when dealing with multi-valued fields.  The &lt;CODE&gt;stats&lt;/CODE&gt; command will multi-valued fields properly.  So &lt;CODE&gt;| stats values(ip)&lt;/CODE&gt; is probably preferable.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 23:22:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14211#M1469</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-25T23:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find all unique IP addresses in a file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14212#M1470</link>
      <description>&lt;P&gt;In theory, Splunk should have automatically extracted the srcip and dstip as fields.   The basic commands to get a list of unique values is to use the chart and dedup command.  However, you want to list those individual fields as the same field which could require some eval and case statements.   For just a single field, you could probably do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=/your/log/file.txt | dedup srcip | chart count by srcip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 May 2010 23:22:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14212#M1470</guid>
      <dc:creator>Simeon</dc:creator>
      <dc:date>2010-05-25T23:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find all unique IP addresses in a file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14213#M1471</link>
      <description>&lt;P&gt;Hmm.  I think you either want just &lt;CODE&gt;dedup&lt;/CODE&gt; to get a single list of values.  Or use the &lt;CODE&gt;chart&lt;/CODE&gt; command.  Using both, as shown, the count will always be 1 for each value of &lt;CODE&gt;scrip&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 23:41:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14213#M1471</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-25T23:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find all unique IP addresses in a file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14214#M1472</link>
      <description>&lt;P&gt;&lt;CODE&gt;eval&lt;/CODE&gt; &lt;CODE&gt;split&lt;/CODE&gt; is new in 4.1, but older versions can use &lt;CODE&gt;makemv&lt;/CODE&gt; to do the same thing.&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2010 20:35:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-all-unique-IP-addresses-in-a-file/m-p/14214#M1472</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-05-26T20:35:55Z</dc:date>
    </item>
  </channel>
</rss>

