Network engineer here.
By default most Cisco devices advertise Cisco Discovery Protocol (CDP) information. That’s a layer-2 multicast advertisement. Seeing what Cisco devices are connected to a Cisco device with an Ethernet cable is as simple as typing in “show cdp neighbors”.
Many network devices also advertise LLDP (link layer discovery protocol) information, an industry standard protocol similar to CDP.
Both these protocols can be turned off “no CDP run” but plugging network equipment together can cause outages: as a network administrator I ask you not to turn off the information we need to combat outages.
It’s also possible to detect switches because they talk the spanning tree protocol (bpdu-guard/port security feature can detect spanning tree and disable the port automatically). Even Mac addresses are assigned to different vendors and (sometimes) can be looked up to identify a probable network device. I remember one old deployment where access points were automatically blocked by Mac-address. But that’s no longer effective given the number of AP vendors now.
Another technique is to block ports based on the number of Mac addresses seen on the port.
When ports are automatically blocked they go into “errordisable” state. By default they do not recover until the next network device reboot (rare) but common practice is to enable “errordisable timeout” to a few hours to “discourage” the behavior without expending man-hours manually reenabling ports.
Another technique is to not offer dhcp leases to particular types of requests. I remember a dhcp setup where windows machines would not get dhcp leases. But I don’t have details how that was implemented.