Retrieving NIC information using SNMP queries


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Environment: VC6

For networking applications, the need to know what NICs are in a system is critical so that sockets can be bound to the proper device. Windows programming allows many ways to retrieve information about each NIC, but there is one way that seems to be the preferred method for Microsoft. The IPCONFIG program, which comes with Windows NT/2000, and the WINIPCFG program, which comes with Windows 9x/ME, both use a DLL called INETMIB1.DLL to retrieve information about each NIC using SNMP queries.

I created this program with the help of information I found in several places on Internet, mostly from posts on CodeGuru.com by Stas Khirman and Quinton Tormanen. The sample code didn't quite suit my needs, so I modified it. The source code and executable in the ZIP file allow all NIC information to be retrieved with two function calls: GetNICCount() and GetNICInfo().


Download source - 24 Kb


  • HELP!!

    Posted by Legacy on 02/18/2004 08:00am

    Originally posted by: Nalli

    I want to obtain the CPU usage of all the Computers in a Lan network using MIB!!!

  • Some machines show wrong description

    Posted by Legacy on 02/04/2004 08:00am

    Originally posted by: Annit Bhattacharya

    Some computers show "NDIS 5.0 Driver" as the description instead of the real one as shown by IPCONFIG. I did an SNMP walk and saw that this the entry only contained "MS TCP Loopback interface" and "NDIS 5.0 driver" so the code is ok.

    Is there any way to get the MAC description as reported by IPCONFIG?

  • How to get SNMP more information, top ten talkers in a network and more...

    Posted by Legacy on 12/06/2003 08:00am

    Originally posted by: balazs

    How to get SNMP info:
    -info about other computers
    -top ten talkers in a network,
    -number of packege send/receive
    -and more statistic?


  • How to use SNMP to get the network hierarchy?

    Posted by Legacy on 05/26/2003 07:00am

    Originally posted by: Cristi

    I tried other methods than SNMP but I couldn't get pass a switch.
    Thank's at least for reading this.

  • How to get SNMP info about other computers

    Posted by Legacy on 11/06/2002 08:00am

    Originally posted by: Marek Mondok

    Can I get subnet mask, card description, speed rate, duplex mode, type, MAC address and other info about other (remote) computers in network?
    How to use SNMP in this case?

  • Doesn't work under Win 95

    Posted by Legacy on 05/08/2002 07:00am

    Originally posted by: Asif Ahsan

    It seems to work okay under Win 98/98SE/ME/2K and XP but I couldn't make it work under Win 95 a,b and c. If I select LOOPBACK ADAPTERS and DIALUP ADAPTERS and if the system has an Ethernet Card (NIC) installed, ViewNIC returns all invalid information about the Ethernet Device. If I do not select LOOPBACK and DIALUP ADAPTERS or If I just select any one of those ViewNIC returns all invalid information. Anyone knows why ?

    Asif Ahsan

  • get Same info in C# with much less effort

    Posted by Legacy on 04/28/2002 07:00am

    Originally posted by: Mark Brooks

    Here is a different approach to the same problem using the new .net System.Management calls. The code is c#... but C++ should be similar.

    Here is the c# code to get the Mac ID:

    public string GetMacID()

    ManagementObjectSearcher query =

    new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration") ;

    ManagementObjectCollection queryCollection = query.Get();

    foreach( ManagementObject mo in queryCollection )


    // MacAddress

    Console.WriteLine( "MacAddress {0}", mo["MacAddress"]);


  • Bug fix for a crash - esp. for logical adapters

    Posted by Legacy on 02/05/2002 08:00am

    Originally posted by: Shaun Staley

    I found a bug with the code. I noticed on some machines that it would crash. Those machines had logical PPP adapters on them. The machines without out the logical PPP adapters worked great.

    When debugging I looked at:
    UINT MibII::GetNICCount(BOOL bDialup, BOOL bLoopback)

    It appeared to work ok, however I think that the correct fix may need to be in that method.

    The problem was in:
    void MibII::GetNICInfo(tSTRUCTNICINFO *pNICInfo)

    This section of code here is the problem:
    // Find the Interface Entry Number that matches the Interface Index.
    for (j = 0; j < m_ifCount; j++)
    if (m_ifIndex[i] == m_ifEntryNum[j])

    That code assumes that it will find the adapter. However, with the PPP adapters installed, it wouldn't find it. So it would grab some piece of memory and try to do a memcpy on it below. The data was all garbage. So what you need to do is add the following after that for loop:

    // Couldn't find one that match.
    if (j == m_ifCount)

    That will skip that adapter and go on the next. That's fine since it's garbage anyway.

    This fix works, but it's not the best one. It should be fixed where the problem occurs. Since I was under a time constraint I didn't bother investigating too deeply.

    I hope it fixes any problems you may have.

  • How can I verify that a GateWay IP is a real one

    Posted by Legacy on 12/18/2001 08:00am

    Originally posted by: Oren Farber

    Hi all

    I get the default gateway using snmp .
    How can I verify that a GateWay IP is a real IP
    and if it not a real IP how can I get my real gate way address


  • Another BUG correction

    Posted by Legacy on 11/14/2001 08:00am

    Originally posted by: Adam Peterson

    Inside the function: int CViewNICDlg::GetNICInfo()

    Add the line : memset(m_pNICInfo, 0, sizeof(tSTRUCTNICINFO) * m.GetIPCount());

    After the memory is allocated : m_pNICInfo = new tSTRUCTNICINFO [m.GetIPCount()];

    NOTE: this is including the fix noted earlier about using m_ifCount to get the count of IP addresses, just added a function GetIPCount() to return this value.

    Problem was if a NIC didn't have a valid IP address like in the middle of a "ipconfig /release_all" the structure was filled with random data and since a loop depended on the MAC address length being filled out correctly app would get an access violation and a crash.

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date