{"id":3899,"date":"2021-11-11T18:56:19","date_gmt":"2021-11-12T00:56:19","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=3899"},"modified":"2021-11-11T18:58:55","modified_gmt":"2021-11-12T00:58:55","slug":"get-list-of-ip-dhcp-leases-from-mikrotik-routeros-command-line","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/get-list-of-ip-dhcp-leases-from-mikrotik-routeros-command-line\/","title":{"rendered":"Get list of IP DHCP Leases from Mikrotik RouterOS Command Line"},"content":{"rendered":"\n<p>Sometimes it is nice to have a list of just the IP addresses and the hostname or mac address.  Can be especially helpful when you are trying to get a list of devices to do a bulk update in LibreNMS.  Helpful LibreNMS links for <a href=\"https:\/\/www.incredigeek.com\/home\/librenms-rename-host-from-command-line\/\">renaming <\/a>and <a href=\"https:\/\/www.incredigeek.com\/home\/show-down-devices-from-ssh-librenms\/\">showing down devices<\/a><\/p>\n\n\n\n<p>we are going to run the command to pull the DHCP information and then use Unix utilities to parse the data out.<\/p>\n\n\n\n<p>Replace dhcp8 with the correct dhcp server in the mikrotik.<\/p>\n\n\n\n<p>First, SSH into your Mikrotik router.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ssh user@mikrotik<\/pre>\n\n\n\n<p>Next we&#8217;ll want to go to the ip dhcp-server lease directory<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/ip dhcp-server lease<\/pre>\n\n\n\n<p>Now we can run the following command to loop through and pull out all the info we need.<br>You can change the info like &#8220;mac-address&#8221; for something like &#8220;status&#8221;.  You can use Tab to see what options are available.  Just delete mac-address and hit tab twice.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">:foreach i in=[find] do={ :put ([get $i address].\",\".[get $i mac-address].\",\".[get $i server].\",\".[get $i host-name ])}<\/pre>\n\n\n\n<p>Found the above helpful info from the following pdf file.<\/p>\n\n\n\n<p><a href=\"https:\/\/mum.mikrotik.com\/presentations\/PH18\/presentation_5113_1516612695.pdf\">https:\/\/mum.mikrotik.com\/presentations\/PH18\/presentation_5113_1516612695.pdf<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes it is nice to have a list of just the IP addresses and the hostname or mac address. Can be especially helpful when you are trying to get a list of devices to do a bulk update in LibreNMS. &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/get-list-of-ip-dhcp-leases-from-mikrotik-routeros-command-line\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[352,452],"tags":[8,744,1260,301,388,173],"class_list":["post-3899","post","type-post","status-publish","format-standard","hentry","category-librenms","category-mikrotik","tag-command-line-2","tag-dhcp","tag-lease","tag-mikrotik","tag-routeros","tag-script"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=3899"}],"version-history":[{"count":3,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3899\/revisions"}],"predecessor-version":[{"id":4232,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3899\/revisions\/4232"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=3899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=3899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=3899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}