{"id":398,"date":"2021-12-29T11:08:33","date_gmt":"2021-12-29T10:08:33","guid":{"rendered":"http:\/\/www.andreazin.it\/solutions\/?p=398"},"modified":"2021-12-29T12:03:23","modified_gmt":"2021-12-29T11:03:23","slug":"get-microtik-switch-ip-address-from-a-script","status":"publish","type":"post","link":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html","title":{"rendered":"Get Microtik Switch Ip Address from a script"},"content":{"rendered":"\n<p>I&#8217;ve spent a couple of hours searching for the right way to grab the IP address of my Microtik switch directly from a script (in Mikrotik scripting language) without success.<\/p>\n<p>The big problem is that the system Ip address of a switch is bound to a specific interface and it could be any ethernet port (from ether1 to etherN) or also the bridge.<\/p>\n<p>Here it is! This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface. I find it very useful to print the IP address of the switch in the email.<\/p>\n<pre>:local ip<br \/>:local iAdd [:toarray [\/ip address find where interface~\"ether\" || interface~\"bridge\"]]<br \/><br \/>:foreach i in=$iAdd do={<br \/>:set ip[\/ip address get $i address]<br \/>:set ip[:pick $ip 0 ([:len $ip]-3) ];<br \/>:log info \"Current IP for interface $i is $ip\"<br \/>}<\/pre>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve spent a couple of hours searching for the right way to grab the IP address of my Microtik switch directly from a script (in Mikrotik scripting language) without success. The big problem is that the system Ip address of &hellip; <a href=\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\">Continua a leggere<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[76,77],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-varie-consigli","tag-microtik","tag-script"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get Microtik Switch Ip Address from a script - Note book<\/title>\n<meta name=\"description\" content=\"This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Microtik Switch Ip Address from a script - Note book\" \/>\n<meta property=\"og:description\" content=\"This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\" \/>\n<meta property=\"og:site_name\" content=\"Note book\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-29T10:08:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-29T11:03:23+00:00\" \/>\n<meta name=\"author\" content=\"Andrea Zin\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrea Zin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\"},\"author\":{\"name\":\"Andrea Zin\",\"@id\":\"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/966ab2f8a9e3b75fe3510736ee2b71c5\"},\"headline\":\"Get Microtik Switch Ip Address from a script\",\"datePublished\":\"2021-12-29T10:08:33+00:00\",\"dateModified\":\"2021-12-29T11:03:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\"},\"wordCount\":116,\"commentCount\":0,\"keywords\":[\"Microtik\",\"Script\"],\"articleSection\":[\"Varie\"],\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\",\"url\":\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\",\"name\":\"Get Microtik Switch Ip Address from a script - Note book\",\"isPartOf\":{\"@id\":\"https:\/\/www.andreazin.it\/solutions\/#website\"},\"datePublished\":\"2021-12-29T10:08:33+00:00\",\"dateModified\":\"2021-12-29T11:03:23+00:00\",\"author\":{\"@id\":\"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/966ab2f8a9e3b75fe3510736ee2b71c5\"},\"description\":\"This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface\",\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.andreazin.it\/solutions\/#website\",\"url\":\"https:\/\/www.andreazin.it\/solutions\/\",\"name\":\"Note book\",\"description\":\"Appunti di un ICT Manager\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.andreazin.it\/solutions\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/966ab2f8a9e3b75fe3510736ee2b71c5\",\"name\":\"Andrea Zin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/35559963b7e995485d1376702641798b8aa665b41038aa231967eb9a354a3a6e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/35559963b7e995485d1376702641798b8aa665b41038aa231967eb9a354a3a6e?s=96&d=mm&r=g\",\"caption\":\"Andrea Zin\"},\"url\":\"https:\/\/www.andreazin.it\/solutions\/author\/andrea-zin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Microtik Switch Ip Address from a script - Note book","description":"This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html","og_locale":"it_IT","og_type":"article","og_title":"Get Microtik Switch Ip Address from a script - Note book","og_description":"This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface","og_url":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html","og_site_name":"Note book","article_published_time":"2021-12-29T10:08:33+00:00","article_modified_time":"2021-12-29T11:03:23+00:00","author":"Andrea Zin","twitter_misc":{"Scritto da":"Andrea Zin","Tempo di lettura stimato":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html#article","isPartOf":{"@id":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html"},"author":{"name":"Andrea Zin","@id":"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/966ab2f8a9e3b75fe3510736ee2b71c5"},"headline":"Get Microtik Switch Ip Address from a script","datePublished":"2021-12-29T10:08:33+00:00","dateModified":"2021-12-29T11:03:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html"},"wordCount":116,"commentCount":0,"keywords":["Microtik","Script"],"articleSection":["Varie"],"inLanguage":"it-IT","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html","url":"https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html","name":"Get Microtik Switch Ip Address from a script - Note book","isPartOf":{"@id":"https:\/\/www.andreazin.it\/solutions\/#website"},"datePublished":"2021-12-29T10:08:33+00:00","dateModified":"2021-12-29T11:03:23+00:00","author":{"@id":"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/966ab2f8a9e3b75fe3510736ee2b71c5"},"description":"This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface","inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.andreazin.it\/solutions\/get-microtik-switch-ip-address-from-a-script.html"]}]},{"@type":"WebSite","@id":"https:\/\/www.andreazin.it\/solutions\/#website","url":"https:\/\/www.andreazin.it\/solutions\/","name":"Note book","description":"Appunti di un ICT Manager","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.andreazin.it\/solutions\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/966ab2f8a9e3b75fe3510736ee2b71c5","name":"Andrea Zin","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/www.andreazin.it\/solutions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/35559963b7e995485d1376702641798b8aa665b41038aa231967eb9a354a3a6e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/35559963b7e995485d1376702641798b8aa665b41038aa231967eb9a354a3a6e?s=96&d=mm&r=g","caption":"Andrea Zin"},"url":"https:\/\/www.andreazin.it\/solutions\/author\/andrea-zin"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6bwSK-6q","_links":{"self":[{"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":2,"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/posts\/398\/revisions\/402"}],"wp:attachment":[{"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.andreazin.it\/solutions\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}