<?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 How to convert IP to decimal in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684511#M233659</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My lookup table has fields of src_ip, dst_ip, and description.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;src_ip=192.168.1.1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;dst_ip=192.168.1.100&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;description="internal IP"&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to convert the src_ip field and dst_ip to decimal.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you know how to convert it, please add a reply.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2024 13:30:34 GMT</pubDate>
    <dc:creator>KwonTaeHoon</dc:creator>
    <dc:date>2024-04-17T13:30:34Z</dc:date>
    <item>
      <title>How to convert IP to decimal</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684511#M233659</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My lookup table has fields of src_ip, dst_ip, and description.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;src_ip=192.168.1.1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;dst_ip=192.168.1.100&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;description="internal IP"&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to convert the src_ip field and dst_ip to decimal.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you know how to convert it, please add a reply.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 13:30:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684511#M233659</guid>
      <dc:creator>KwonTaeHoon</dc:creator>
      <dc:date>2024-04-17T13:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert IP to decimal</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684514#M233661</link>
      <description>&lt;P&gt;Take a look at this solution:&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Convert-Hexadecimal-IP-v4-addresses-to-decimal/td-p/40938" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/Convert-Hexadecimal-IP-v4-addresses-to-decimal/td-p/40938&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;You could use:&amp;nbsp;&amp;nbsp;(?&amp;lt;d1&amp;gt;\d{1,3})\.(?&amp;lt;d2&amp;gt;\d{1,3})\.(?&amp;lt;d3&amp;gt;\d{1,3})\.(?&amp;lt;d4&amp;gt;\d{1,3}) for your particular example as the rex conversion.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=1
| eval src_ip = "192.168.1.1"
| streamstats values(src_ip) as src_ip by _time
| rex field=src_ip "(?&amp;lt;d1&amp;gt;\d{1,3})\.(?&amp;lt;d2&amp;gt;\d{1,3})\.(?&amp;lt;d3&amp;gt;\d{1,3})\.(?&amp;lt;d4&amp;gt;\d{1,3})"
| eval dec_src_ip = 'd1'*16777216+'d2'*65536+'d3'*256+'d4'+0&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;There is also an app that provides you a command to do the conversion:&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;A href="https://splunkbase.splunk.com/app/512" target="_blank" rel="noopener"&gt;https://splunkbase.splunk.com/app/512&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 14:46:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684514#M233661</guid>
      <dc:creator>jason_hotchkiss</dc:creator>
      <dc:date>2024-04-17T14:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert IP to decimal</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684587#M233681</link>
      <description>&lt;P&gt;Let me give this a semantic makeover using &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/BitFunctions#bit_shift_left.28.26lt.3Bvalue.26gt.3B.2C_.26lt.3Bshift_offset.26gt.3B.29" target="_blank" rel="noopener"&gt;bit_shift_left&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; (9.2 and above - thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/226579"&gt;@jason_hotchkiss&lt;/a&gt; for noticing) because semantic code is easier to understand and maintain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval offset = mvappend("24", "16", "8")
| eval segment_rev = mvrange(0, 3)
| foreach *_ip
    [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = split(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "."),
    &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;_dec = sum(mvmap(segment_rev, bit_shift_left(tonumber(mvindex(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, segment_rev)), tonumber(mvindex(offset, segment_rev)))), tonumber(mvindex(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, 3))),
    &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = mvjoin(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, ".") ``` this last part for display only ```]
| fields - offset segment_rev&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sample data gives&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;dst_ip&lt;/TD&gt;&lt;TD&gt;dst_ip_dec&lt;/TD&gt;&lt;TD&gt;src_ip&lt;/TD&gt;&lt;TD&gt;src_ip_dec&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;192.168.1.100&lt;/TD&gt;&lt;TD&gt;3232235876&lt;/TD&gt;&lt;TD&gt;192.168.1.1&lt;/TD&gt;&lt;TD&gt;3232235777&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation you can play with and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="src_ip, dst_ip
192.168.1.1, 192.168.1.100"
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: If it helps readability., you can skip foreach and spell the two operations separately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval offset = mvappend("24", "16", "8")
| eval segment_rev = mvrange(0, 3)
| eval src_ip = split(src_ip, ".")
| eval dst_ip = split(dst_ip, ".")
| eval src_ip_dec = sum(mvmap(segment_rev, bit_shift_left(tonumber(mvindex(src_ip, segment_rev)), tonumber(mvindex(offset, segment_rev)))), tonumber(mvindex(src_ip, 3)))
| eval dst_ip_dec = sum(mvmap(segment_rev, bit_shift_left(tonumber(mvindex(dst_ip, segment_rev)), tonumber(mvindex(offset, segment_rev)))), tonumber(mvindex(dst_ip, 3)))
| eval src_ip = mvjoin(src_ip, "."), dst_ip = mvjoin(dst_ip, ".") ``` for display only ```
| fields - offset segment_rev&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 16:40:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684587#M233681</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-04-18T16:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert IP to decimal</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684648#M233708</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval offset = mvappend("24", "16", "8")
| eval segment_rev = mvrange(0, 3)
| eval offset = mvappend("24", "16", "8")
| eval segment_rev = mvrange(0, 3)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;For the above, should the second set have been given a different value for the field?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Additionally, when I run the example, I received:&lt;BR /&gt;&lt;BR /&gt;04-18-2024 13:36:06.590 ERROR EvalCommand [102993 searchOrchestrator] - The 'bit_shift_left' function is unsupported or undefined.&lt;BR /&gt;&lt;BR /&gt;I believe the function requires 9.2.0+&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 13:40:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684648#M233708</guid>
      <dc:creator>jason_hotchkiss</dc:creator>
      <dc:date>2024-04-18T13:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert IP to decimal</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684689#M233712</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;04-18-2024 13:36:06.590 ERROR EvalCommand [102993 searchOrchestrator] - The 'bit_shift_left' function is unsupported or undefined.&lt;BR /&gt;&lt;BR /&gt;I believe the function requires 9.2.0+&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thanks for noticing!&amp;nbsp; I always assumed that bitwise operations had been part of SPL from day one but no.&amp;nbsp; The document has this footer: "&lt;SPAN&gt;This documentation applies to the following versions of Splunk&lt;/SPAN&gt;®&lt;SPAN&gt; Enterprise: 9.2.0, 9.2.1&lt;/SPAN&gt;." (Searching in previous versions results in the same pointers to 9.2.)&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;For the above, should the second set have been given a different value for the field?&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Those are really bad copy-and-paste errors.&amp;nbsp; Corrected.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 16:47:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-IP-to-decimal/m-p/684689#M233712</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-04-18T16:47:49Z</dc:date>
    </item>
  </channel>
</rss>

