title: How to parse a particular MAC address from DHCP lease file in Openwrt?
body: <p>I am trying to write a script to parse some of devices from DHCP lease file in Openwrt with corresponding addresses . I am maintain a list with some vendor MAC address . When i connect a device to the router , i want to fetch the IP address ,MAC address and Name of that device using the vendor MAC from DHCP lease file . </p>
  
  <p>For example , if i have maintained list of Vendor MAC address like </p>
  
  <pre><code>MAC LIST =  {"00:01:0A","00:00:1A","00:00:39"}
  where ,
      00:01:0A - CISCO
      00:00:1A - AMD  
      00:00:39 - Toshiba TOSHIBA CORPORATION
  </code></pre>
  
  <p>and in Openwrt dhcp lease file contain different device <strong>for example</strong>:</p>
  
  <pre><code>root@OpenWrt:/# cat /tmp/dhcp.leases
  
  1568953482  70:B3:D5:14:D0:31 192.168.3.51 device1 01:70:B3:D5:14:D0:31
  2867821468  38:B8:EB:10:00:22 192.168.5.93 device2 01:38:B8:EB:10:00:22
  8984532872  00:01:0A:33:11:33 192.168.5.44 CISCOee 01:00:01:0A:33:11:33
  
  Where, 2nd column - MAC address , 3rd column - IP address and 4th column- Name
  </code></pre>
  
  <p>Here i am getting a CISCO device with a MAC address starting from  <code>00:01:0A</code> . I want to write a bash script in openwrt/Unix to fetch the corresponding IP address ,name and MAC address of all the Device with respect to the <code>MAC LIST</code> from <code>/tmp/dhcp.leases</code> file . If no device found with reset to <code>MAC LIST</code> , the script should return <code>NULL</code> . How can i parse this Address list using script ? Any suggestions ? </p>
  
  <p><strong>update :</strong> </p>
  
  <p>I want to compare the first 3 digit of Vendor MAC address with dhcp leases file . For example  my list contain following vendor MAC address (<em>3 digit</em>) in MAC.txt file :</p>
  
  <pre><code>/usr/MAC.txt
  ---------
  
       00:01:0A
       00:00:1A
       00:00:39
  </code></pre>
  
  <p>and the dhcp.leases contain :</p>
  
  <p>root@OpenWrt:/# cat /tmp/dhcp.leases</p>
  
  <pre><code>1568953482  70:B3:D5:14:D0:31 192.168.3.51 device1 01:70:B3:D5:14:D0:31
  2867821468  38:B8:EB:10:00:22 192.168.5.93 device2 01:38:B8:EB:10:00:22
  8984532873  00:01:0A:33:11:33 192.168.5.44 CISCOee1 01:00:01:0A:33:11:33
  8984532874  00:01:0A:34:12:34 192.168.5.44 CISCOee2 01:00:01:0A:34:12:34
  </code></pre>
  
  <p>Now i want to compare dhcp leases file MAC address from MAC.txt file with dhcp.leases file . If <em>first 3 digit matching</em> , then i want to return the IP address , MAC address and Name of matching device . </p>
  
  <pre><code>Sample output :
  
           00:01:0A:33:11:33 192.168.5.44 CISCOee1
           00:01:0A:34:12:34 192.168.5.44 CISCOee2
  </code></pre>
  
  <p>if nothing found send NULL as output .</p>