Skip to content
May 22 / Greg

Using Mikrotik To Discover VLANs

Occasionally I’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).
There are many ways to do this, but I figured this is a fairly simple one that doesn’t tax small devices too much.

Mikrotik Config

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

I then created a DHCP client interface.

Now that I have that configured I wrote a simple script that will do all the work for me:

1
2
3
4
5
6
7
8
9
10
11
:local i 2
:local x 200
:log info snooping-start
/ip dhcp-client enable [/ip dhcp-client find interface=vlan-wlan-test]
while ($i < $x) do={
  /interface vlan set vlan-wlan-test vlan-id=$i
  :log info "snooping $i"
  :set $i ($i + 1)
  :delay 5000ms
}
/ip dhcp-client disable [/ip dhcp-client find interface=vlan-wlan-test]

Local i is what VLAN ID to start at.
Local x is the high number VLAN ID to stop at.
The 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’s done it will disable the DHCP client.
The DHCP client will add an entry to the log if it is able to pull an IP.
So 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.

Conclusion

So this isn’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.
Let me know what you would do differently, how would you modify it?
Thanks and happy VLAN finding.

Leave a Comment

 

*