This query will list the total number of hosts reporting to the indexer for any specified time range.
This only works for universal forwarders. If you have hosts reporting in over syslog (typically port 514) they will not be listed.
index=_internal sourcetype=splunkd | stats dc(hostname) as "Number of Hosts"
The same splunk result can be achieved other splunk commands as listed in http://www.cloudibee.com/splunk-search-cheatsheet/.
Example : List all hosts that are logging to a particular index. In this example ,we use apachelog as the index.
index=apachelog| table host | dedup host
index=apachelog | stats count by host
Hope this helps and you can add it here too.