This project is read-only.

Project Description

A very simple MAC to IP address mapping utility

The issue

I write software that connects to real time data acquisition peripherals. Most of these now use TCP/IP, but they are no "real" PCs so they can't register themselves to a domain. When I install them at a customer site, I usually have no choice, they need to be connected to the local network, but no one at the IP department wans to give me fixed IP addresses. I need to use their DHCP policy.

The only practical solution is usually to hope that the IP address won't change and to type it directly in the appropriate configuration file. This scheme usually fails at some point, and the customer calls saying that data acquisition no longer works.

The theoretical solution is very simple. You connect using the MAC address that never changes instead of the IP address. Unfortunately, if there is a standardized way to retrieve the MAC address from the IP address (ARP packets) the reverse is not possible.

This is why I wrote a little utility to scan a network and gather MAC addresses corresponding to IP addresses, so I can easily make the reverse lookup myself.

What MacNS will do

  • MacNS will regularly scan the subnet it sits on, and records the corresponding MAC addresses.
  • MacNS saves these in a LMHOSTS-like file, so that the local machine can use this information to retrieve the IP address corresponding to a MAC address.
  • MacNS will use processor time and network bandwidth when run. It will take up space on your hard disk, even when it is not running.

What MacNS will NOT do

  • MacNS will not work on Linux, Mono, Macintosh, iPhone, or Google Phone. MacNS uses the "SendARP" API which is only available in Windows.
  • MacNS will not work outside the local subnet. The SendARP command will not retrieve MAC addresses across routers.
  • MacNS will not react immediately to IP address changes. MacNS slowly scans the network, and will only discover IP changes when it stumbles upon a new ARP entry.
  • MacNS will not try to be kind to your network administrator. MacNS scans the network. It may be detected as an intrusion, it may fill your ARP cache.
  • MacNS will not act as a DNS server. It only creates a LMHOSTS file that can be used locally. You can however put the created LMHOSTS file on a shared directory.
  • MacNS will not provide a beautiful or responsive user interface. MacNS does not scan the network on a background thread, you will experience delays when it waits for an ARP response (it will not, of course, make other programs become unresponsive.)

Installing MacNS

To install MacNS,
  1. Create a subdirectory to store the executable and data. The default setup expects this directory to be C:\MacNS.
  2. Make sure you have the .NET framework installed. MacNS expects the 3.5 framework to be installed.
  3. Install MacNs.exe and MacNs.exe.config in the created directory.
  4. Change the configuration in the app.config file to match your needs.
    1. HostsFile indicates the name of the lmhosts file to create. You can change this to directly create the lmhosts file in the c:\windows\system32\drivers\etc\ directory, or leave the entry as is, and add an include command in your existing lmhosts file.
    2. Subnet indicates the subnet to scan. This must be in the form "X.Y.Z." with exactly three dots. MacNS will scan the IP addresses from X.Y.Z.1 to X.Y.Z.254
    3. Delay indicates the time to wait, in milliseconds, between two ARP requests, after an initial scan has been done. The initial scan tries to do 20 ARP calls per second. After the first full scan, the delay is applied between two requests.
    4. Filter is a filter on the MAC names. Only MAC names containing the filter will be listed in the lmhosts file.
  5. Optionally change your existing lmhosts file to include the file generated by MacNS.
  6. Start MacNS and leave it running.

Using MacNS

If you have setup your name resolution method to use the lmhosts file generated by MacNS, usage is transparent to applications that use TCP/IP:


If the name resolution works inside MacNS (MAC->IP button) but not in a Windows application, make sure Windows really uses the file MacNS is creating:
  • Check in macns.exe.config that the hosts file is created where you expect it to be.
  • Make sure Windows sees your file:
    • Either make MacNS directly generate the HOSTS or LMHOSTS file in the appropriate Windows directory (c:\windows\system32\drivers\etc\ ) by changing the HostsFile parameter in MacNS.exe.config. Beware that this will erase the previous contents of that file.
    • Or edit the HOSTS or LMHOSTS file to add an #include statement that points to the file MacNS is creating.
  • Make sure Windows really uses the HOSTS or LMHOSTS file.
    • By default, Windows will use it, but you may be on a network where the system administrator has added a policy that prevents Windows from using the file.
    • On 64-bit versions, Windows may use different system directories (I do not have access to a 64 bit windows system to check.) More information here
Microsoft Knowledge base article about the LMHosts file :

Last edited Jan 21, 2010 at 12:39 PM by sleclercq, version 13