Thursday, October 29, 2015

Shell Script - EMail MAC Address and IP Address with Vendor OUI Information

Overview

The purpose of this document is to identify to list all the active MAC Address, IP Address and the hardware vendor information associated with IEEE.

This script will collects information from arp command. Also the script will provide a link to the hardware vendor of the NIC card; which is first 3 octets of MAC Address.
  • IP Address
  • MAC Address
  • Hyperlink to Hardware Vendor

Applies To

CentOS 7, RHEL 7

Pre-requisites

  • arp
  • sendmail
  • tee

Shell Script Snippet

#!/bin/bash

(
printf "<HTML>\n<TITLE>LAN IPs, MAC Address and Hardware Information </TITLE>\n"
printf "<BODY><H1> LAN IPs, MAC Address and Hardware Information</H1>\n"
printf "<TABLE border=1>"
arp -a | awk '{print $2,$4}' | awk -F'[().: ]' '{print "<TR><TD><B>IP Address:</B> </TD><TD width=120px>" $2"."$3"."$4"."$5,"</TD><TD><B>MAC Address: </B></TD><TD width=120px>",$7":"$8":"$9":"$10":"$11":"$12,"</TD>""<TD width=280px><a href=\"http://standards.ieee.org/cgi-bin/ouisearch?"$7$8$9"\">IEEE Hardware Vendor Lookup "$7"-"$8"-"$9"</a></TD></TR>"}'
printf "</TABLE>\n"
printf "\n</BODY>\n</HTML>\n"
) |  tee ${0##*/}.html     # Send Standard Output to file

# Send E-Mail Notification - Snippet
(
  echo From: ReceiptsEMailAddress@domain.com
  echo To: SendersEMailAddress@domain.com
  echo "Content-Type: text/html; "
  echo Subject: IP Address - MAC Address and Hardware Vendor Information
  echo
  cat  ${0##*/}.html    # Set Cat output as a body of the email
) | sendmail -t


SlideShare Information



No comments:

Post a Comment