<?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 Is there a function to check if field is an ip address or hostname? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369007#M108750</link>
    <description>&lt;P&gt;I have a field to evaluate if the value of the field is an IP address or a hostname. if it is an IP address do something, if it is a hostname do something else.&lt;/P&gt;
&lt;P&gt;Is there a eval function to check if field is IP or not?&lt;/P&gt;</description>
    <pubDate>Fri, 31 Mar 2023 14:06:54 GMT</pubDate>
    <dc:creator>brdr</dc:creator>
    <dc:date>2023-03-31T14:06:54Z</dc:date>
    <item>
      <title>Is there a function to check if field is an ip address or hostname?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369007#M108750</link>
      <description>&lt;P&gt;I have a field to evaluate if the value of the field is an IP address or a hostname. if it is an IP address do something, if it is a hostname do something else.&lt;/P&gt;
&lt;P&gt;Is there a eval function to check if field is IP or not?&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 14:06:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369007#M108750</guid>
      <dc:creator>brdr</dc:creator>
      <dc:date>2023-03-31T14:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: is it an ip address or hostname</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369008#M108751</link>
      <description>&lt;P&gt;Could you do something like this?&lt;BR /&gt;
| eval isLocal=if(cidrmatch("10.0.0.0/24",ip), "local", "not local")&lt;/P&gt;

&lt;P&gt;You could try 0.0.0.0/24 and see if that matches any IP address?&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 14:13:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369008#M108751</guid>
      <dc:creator>Heff</dc:creator>
      <dc:date>2018-04-27T14:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: is it an ip address or hostname</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369009#M108752</link>
      <description>&lt;P&gt;You can do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval fieldX = if(match(fieldX, "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"), "do something", "do something else")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#match.28SUBJECT.2C_.22REGEX.22.29"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#match.28SUBJECT.2C_.22REGEX.22.29&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 14:20:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369009#M108752</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-27T14:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: is it an ip address or hostname</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369010#M108753</link>
      <description>&lt;P&gt;perfect. thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 14:25:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/369010#M108753</guid>
      <dc:creator>brdr</dc:creator>
      <dc:date>2018-04-27T14:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: is it an ip address or hostname</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/636883#M221175</link>
      <description>&lt;P&gt;here's what I landed on, in case it's helpful for folks in the future.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval isIPV4 = if(match(IP,"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$"),"True","False")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The best regex for validating IPV4 is an ever-evolving conversation on stack overflow.&amp;nbsp; So, I used the latest from there, but from this highest rated answer, not the accepted one:&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://stackoverflow.com/a/36760050/6376311" target="_blank" rel="nofollow noopener noreferrer"&gt;https://stackoverflow.com/a/36760050/6376311&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since someone mentioned it, in order to validate private/public IPv4, I made myself an eval-based macro with the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;case(
cidrmatch("10.0.0.0/8",$IP$),"False",
cidrmatch("172.16.0.0/12",$IP$),"False",
cidrmatch("192.168.0.0/16",$IP$),"False",
isnull($IP$) OR like($IP$,""), "False",
match($IP$,"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$"),"True")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Then, I can use it in any query like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval Remote_Address_isExternal = `isExternalIPv4(Remote_Address)`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 13:47:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-function-to-check-if-field-is-an-ip-address-or/m-p/636883#M221175</guid>
      <dc:creator>msquicc</dc:creator>
      <dc:date>2023-03-31T13:47:14Z</dc:date>
    </item>
  </channel>
</rss>

