I'm newbie too.
1)I don't know how to discover.I think you must get a seed device at least.Then you can get any other switch or router which connected to this switch via cdp.
2)It can be done by net::snmp,you can do it by get status of the interface via oid.