First, this answer is biased on ethernet networks.
The ideas can be tips also for other scenarios.
There is many ways to accomplish this, for example :
- scanning
- targeted discovery
- passive traffic monitoring
scanning
Possible, for example, with nmap.
Pro :
- Can discover unknown devices and services. forgotten by lazy sysadmins or installed by untrusted users.
- Can be a useful tool to discover services and security audit.
- For newbies, it sounds the best way : start from scratch, find them all. Bad news : read the cons.
Cons:
- It is very inefficient. If you start from scratch - you know nothing about the LAN - and you want to find every possible service, you have to scan almost all the tcp and udp ports for every possible host.
- The results aren't 100 % affordable : hw or sw firewalls; etc... The next run can lead to quite a different result.
- The results aren't a simple i_got_it / null, but fuzzy : you need an expert to evaluate the results.
- Sometimes you must have a admin account on your pc to run this scanning.
- Some IDS can log this activity as bad one.
targeted discovery
If your goal is to map your network, the official services, you can think about their official discovery capabilites. For example CDP, SSDP, srvloc, snmp get broadcast, etc...
You have to know what services you are probing.
Pro:
- This is the most efficient way, both max speed and min network bandwidth.
- The result is reliable : next run must return the same result ( obviously if the services and network stay alive ).
- This is the way to check services availability, and account for SLA.
- You don't need an expert : e.g. if a device answers to snmp get SysDescr, you know your data. You get the exact answer or you miss it.
Cons:
- You have to know what services you are probing.
- You cannot use this to be sure to found devices / services. This is nor a security audit neither a discovery tool. For example : I change my http server listen port to 81, how do you find me ?
passive traffic monitoring
Once upon a time, you find ethernet hosts linked with copper cables ( CAT3 / CAT5 ) to hubs.
You can run on any of these hosts a program to capture all the traffic, putting the ethernet card in promiscous mode, so the NIC pass to the operating system all the packets, also the packets with a MAC destination different than the MAC address of the NIC.
Your program can analyze these raw data, and parse the protocols and packets inside.
Nowadays you use ethernet switches, not hubs. Your pc' NIC in promiscous mode doesn't receive all the traffic on the network, because the switch forwards to you only the packets for your host or for all ( broadcast and - if registered - multicast ).
You have to use managed switches, and configured one port to be a repeater or monitor port, to link the monitoring host.
Pro:
- This is passive monitoring - if done right. This can be useful for specific assessment, where you cannot send any packet on the network under test, and you respect strong SLA.
- To collect the nw traffic, you have not to know the protocols and services configuration. For example, you can remove from your host the tcp/ip stack, leave the driver of your ethernet card, and collect the traffic.
- Using managed switch with a monitor port, you don't have to put the NIC in promiscous mode / tweak you tcp/ip stack.
- libpcap / winpcap is the de facto standard to capture packets, and it works. You can play with some GUI frontend, like Analyzer or Wireshark, before to develop your own application.
- It ban be a useful tool to discover services and security audit, too.
Cons:
- Do you have to be sure to not send packets on the network under test ? Use a managed switch with a repeater port, also if you have hubs. The repeater port can only receive network traffic.
- To capture a high troughput of data, like on 1 Gbit, you have to tweak your operating system configuration, otherwise cpus rise to full load and you still loose packets. Forgot ms windows for this stuff.
- Obviously, you see only the live traffic, nothing about services not transmitting.
- See the Cons 3, 4 of scanning. This is near to watch the bits on the wires, it is like the oscilloscope for electronic engineers. You capture all the data, later you need a expert^2 to evaluate them. Yes, later, because analyzing in detail the errors and glitches is very time consuming.
This is a simple discovery for dummies intro. Discovery tools can mix both ways to look for devices and services on the network.
For example, HP JetAdmin discovery uses different methods only to look for HP network printers and scanners not for all the devices on your LAN.