"If You Only Knew the Power of the Command Line!"

At its core, the command line interface (CLI) grants users control over complex systems, and allows for the automation of tasks that would otherwise be cumbersome to manage manually. What follows is a brief transcript that helps to illustrate the point.

last | awk '{print $3}' |grep -E '128.122..'|sort -V |uniq >> publicIPs

Here, from our host node, we get a list of logins via the last command, extracting only the third (3rd) column of the output via awk, then grep for IPs on the 128.122 subnet. From there, we sort said IPs numerically, and output uniq IPs to a list ("publicIPs"). For reference:

128.122.87.178
128.122.113.43
128.122.113.212
128.122.114.69
128.122.114.139
128.122.115.60

Next, let's iterate through this list (by line), performing an nslookup on each IP, and parse our region of interest (ROI),then add this ROI to a file ("dnsRecs").

while IFS= read -r line; do
  nslookup "$line" |awk 'FNR == 1 {print $4}' >> dnsRecs
done < publicIPs

By way of example (FQDN omitted):

plabrigla
publio
tamino
figaro
keystone
syndrome

Then, let's iterate through the list of DNS records, using nmap to gather some intelligence on the hosts:

while IFS= read -r line; do
  echo "$line" >> osRecs
  nmap -O "$line" >> osRecs
done < dnsRecs

For reference (single host, DNS ommitted):

Not shown: 996 closed ports
PORT      STATE    SERVICE
22/tcp    filtered ssh
3283/tcp  open     netassistant
5900/tcp  open     vnc
28201/tcp open     unknown
Aggressive OS guesses: VMware ESXi 3.5 (91%), FreeBSD 6.1-RELEASE (88%),   FreeBSD 6.2-RELEASE (88%), Apple iOS 4.3.1 - 4.3.5 (87%), 
Apple iOS 6 (87%), Apple iOS 8.2 (Darwin 14.0.0) (87%), Apple OS X 10.10 (Yosemite) or iOS 8.3 - 9.0.1 (Darwin 14.0.0 - 15.0.0) (87
%), Apple iPhone OS 3.1.2 - iOS 4.2.1 (87%), Apple Mac OS X 10.5 (Leopard) (Darwin 9.2.2, x86) (87%), Apple Mac OS X 10.5.5 (Leopar
d) - 10.6.6 (Snow Leopard) (Darwin 9.5.0 - 10.6.0) (87%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 8 hops

Cheers.