{"id":7479,"date":"2023-05-22T08:59:17","date_gmt":"2023-05-22T14:59:17","guid":{"rendered":"https:\/\/gregsowell.com\/?p=7479"},"modified":"2023-05-22T08:59:17","modified_gmt":"2023-05-22T14:59:17","slug":"using-mikrotik-to-discover-vlans","status":"publish","type":"post","link":"https:\/\/gregsowell.com\/?p=7479","title":{"rendered":"Using Mikrotik To Discover VLANs"},"content":{"rendered":"<p>Occasionally I&#8217;ll be in an unfamiliar place and I want to plug into a switch and see what VLANs a trunk port will give me(I can also use this on wireless occasionally).<br \/>\nThere are many ways to do this, but I figured this is a fairly simple one that doesn&#8217;t tax small devices too much.<\/p>\n<h2>Mikrotik Config<\/h2>\n<p>First thing I did was add a VLAN interface(which is virtual) to the physical interface my resource lives on.  In my case it was just WLAN1<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_1-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_1-1-300x208.jpg\" alt=\"\" width=\"300\" height=\"208\" class=\"aligncenter size-medium wp-image-7480\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_1-1-300x208.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_1-1.jpg 675w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I then created a DHCP client interface.<br \/>\n<a href=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_2-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_2-1-300x174.jpg\" alt=\"\" width=\"300\" height=\"174\" class=\"aligncenter size-medium wp-image-7481\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_2-1-300x174.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2023\/05\/Screenshot_2-1.jpg 346w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now that I have that configured I wrote a simple script that will do all the work for me:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">:local i 2\r\n:local x 200\r\n:log info snooping-start\r\n\/ip dhcp-client enable [\/ip dhcp-client find interface=vlan-wlan-test]\r\nwhile ($i &lt; $x) do={\r\n  \/interface vlan set vlan-wlan-test vlan-id=$i\r\n  :log info &quot;snooping $i&quot;\r\n  :set $i ($i + 1)\r\n  :delay 5000ms\r\n}\r\n\/ip dhcp-client disable [\/ip dhcp-client find interface=vlan-wlan-test]<\/code><\/pre>\n<p>Local i is what VLAN ID to start at.<br \/>\nLocal x is the high number VLAN ID to stop at.<br \/>\nThe idea is this script will enable the DHCP client, set the VLAN interface ID to the low number, sit there for 5 seconds, move to the next VLAN ID, and when it&#8217;s done it will disable the DHCP client.<br \/>\nThe DHCP client will add an entry to the log if it is able to pull an IP.<br \/>\nSo I can fire off the script, come back later and the log will tell me the VLAN ID along with the IP subnet it found there.<\/p>\n<h2>Conclusion<\/h2>\n<p>So this isn&#8217;t the most elegant way to perform the action, but it is pretty simple.  It is predicated on the idea that DHCP must be there, so it could be modified to possibly do some snooping on each to find traffic.<br \/>\nLet me know what you would do differently, how would you modify it?<br \/>\nThanks and happy VLAN finding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Occasionally I&#8217;ll be in an unfamiliar place and I want to plug into a switch and see what VLANs a trunk port will give\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,35],"tags":[],"class_list":["post-7479","post","type-post","status-publish","format-standard","hentry","category-mikrotik","category-script"],"_links":{"self":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/7479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7479"}],"version-history":[{"count":1,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/7479\/revisions"}],"predecessor-version":[{"id":7482,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/7479\/revisions\/7482"}],"wp:attachment":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}