Using the FileSystemObject to obtain a DHCP Client's MAC AddressBy Brian Atkinson
This article will look into obtaining the MAC (Media Access Control) Address (see definition of MAC address) from a Network Adapter using one Active Server Page. There are two catches to this solution: The client must be using DHCP to obtain an IP Address, and IIS needs to be running on the same server that the DHCP services are running on. The ASP page will only obtain MAC addresses from clients that were issued an IP address from this same server.
With these points clarified, we will move on to accomplishing the task at
hand. All DHCP leases are logged in the
*.DAY extension represents
any of seven possible extensions for this file -
.Mon .Tue .Wed .Thu .Fri
.Sat .Sun. Open any of these files in a text editor (except the one for the
current day). Scroll down about fifteen lines, and you should see
something like this:
ID,Date,Time,Description,IP Address,Host Name,MAC Address 11,12/25/99,00:04:00,Renew,255.255.255.255,testbench,00C0F0XXYYZZ
There is one little catch to getting information from the current DHCP log. The DHCP log currently in use for the day cannot be directly opened. In other words, dhcpsrvlog.Mon cannot be opened directly on Monday, because it is in use by the DHCP services. Copying it to another location is the way to avoid this problem. The last field of the comma-delimited database reveals the MAC address for the client's machine.
Now that we know this information exists, we can use the ASP to:
1. Obtain the client's IP address and redirect invalid IP ranges to
2. Copy the current DHCP log to a working folder with a randomly generated name
3. Search for the last entry of the client's IP address in the copied DHCP log
4. Extract the MAC address from the last found line with the IP address
5. Delete the temp file created by copying the DHCP log
6. Display the output
This should do the trick. I have used this technique to successfully obtain MAC addresses for Windows 9x/NT, Macintosh and Linux boxes. Macintosh clients sometimes have much longer MAC addresses entries in the DHCP log, but the last 12 characters are always the MAC address.
NTFS permissions required for this example to work:
IUSR must have READ to the
IUSR must have READ, WRITE and DELETE to the