Thursday, August 6, 2020

Report Linux IP, hostname & name servers

This script finds Linux hosts, and reports their IP address, FQDN hostname, name servers and outputs results in CSV format.

Details:
  • nmap is used to scan IP ranges for hosts listing on port 22, then
  • Remote ssh command is run to connect to each host, find FQDN (hostname -f) and configured name severs (resolv.conf)
  • This assumes the user running the script has the privilege to login to each host via SSH
  • The RSA key fingerprint prompt is auto accepted and the RSA key fingerprint is then discarded so that your ~/.ssh/known_hosts file is not filled up with hundreds or thousands of  RSA key fingerprints
  • Results are output to CSV file.