<?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 extract ip address using regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379719#M111202</link>
    <description>&lt;P&gt;Can you please post search code and event strings as code (use the 101010 button in the editor), otherwise some parts will get messed up due to how the board handles certain special characters.&lt;/P&gt;

&lt;P&gt;In general, to strictly extract an IP address, use a regex like this: &lt;CODE&gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So for you example, you should probably use something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="testd" | rex field=_raw "Remote host:(?&amp;lt;Remotehost&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 May 2018 11:18:12 GMT</pubDate>
    <dc:creator>FrankVl</dc:creator>
    <dc:date>2018-05-02T11:18:12Z</dc:date>
    <item>
      <title>How to extract ip address using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379717#M111200</link>
      <description>&lt;P&gt;index="testd" | rex field=_raw "Remote host:(?.*):"  |dedup Remotehost |stats count by Remotehost&lt;/P&gt;

&lt;P&gt;My events:&lt;/P&gt;

&lt;P&gt;Remote host:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;2.136.12.186&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;:34126]@684574 useCount=1 bytesRead=0 bytesWritten=2994631 age=163708ms lastIO=5ms ))).onExceptionWrite exception&lt;/P&gt;

&lt;P&gt;Expected output:&lt;/P&gt;

&lt;P&gt;2.136.12.186&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 11:11:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379717#M111200</guid>
      <dc:creator>karthi2809</dc:creator>
      <dc:date>2018-05-02T11:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ip address using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379718#M111201</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
try with this regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="testd" 
| rex "(?ms)Remote host:\s+(?&amp;lt;Remotehost&amp;gt;\d+\.\d+\.\d+\.\d+)"
| dedup Remotehost 
| stats count by Remotehost
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;that you can test at &lt;A href="https://regex101.com/r/NZkwci/2"&gt;https://regex101.com/r/NZkwci/2&lt;/A&gt;&lt;BR /&gt;
Only one question: why do you dedup by Remotehost and then use stats count? result will be always 1!&lt;/P&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 11:18:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379718#M111201</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2018-05-02T11:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ip address using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379719#M111202</link>
      <description>&lt;P&gt;Can you please post search code and event strings as code (use the 101010 button in the editor), otherwise some parts will get messed up due to how the board handles certain special characters.&lt;/P&gt;

&lt;P&gt;In general, to strictly extract an IP address, use a regex like this: &lt;CODE&gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So for you example, you should probably use something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="testd" | rex field=_raw "Remote host:(?&amp;lt;Remotehost&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 May 2018 11:18:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379719#M111202</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-05-02T11:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ip address using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379720#M111203</link>
      <description>&lt;P&gt;There is literally a million valid regexes on the Internet to extract IP addresses.&lt;/P&gt;

&lt;P&gt;Assuming the following:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;You only have IPv4 addresses&lt;/LI&gt;
&lt;LI&gt;They're always at the beginning of the event&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;You could use this regex: &lt;CODE&gt;^((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Hope that helps - if it does I'd be happy if you would upvote/accept this answer, so others could profit from it. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 11:20:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/379720#M111203</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-02T11:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract ip address using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/707462#M239296</link>
      <description>&lt;P&gt;I created a Splunk Macros&amp;nbsp;for regular expressions for IPv4 addresses.&lt;/P&gt;&lt;P&gt;Definitions and usages are in an article below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;A href="https://qiita.com/Joh256/private/659ef65897905890ef99" target="_blank"&gt;https://qiita.com/Joh256/private/659ef65897905890ef99&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;I also put them in an add-on below.&lt;/P&gt;&lt;P&gt;&lt;A href="https://splunkbase.splunk.com/app/6595" target="_blank"&gt;https://splunkbase.splunk.com/app/6595&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2024 23:04:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-ip-address-using-regex/m-p/707462#M239296</guid>
      <dc:creator>tfujita_splunk</dc:creator>
      <dc:date>2024-12-22T23:04:18Z</dc:date>
    </item>
  </channel>
</rss>

