Get routers mac address?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Get routers mac address?

  1. #1
    Join Date
    Dec 2008

    Get routers mac address?

    I am trying to learn how to build packets, I got everything down except how to get your routers mac address or what ever it uses in the packet.

    How can I get my routers mac address? I am fine with using an external C++/asm dll.

  2. #2
    Join Date
    Jun 2001
    Melbourne/Aus (C# .Net 4.0)

    Re: Get routers mac address?

    When you say 'Your Router' are you talking about the device your computer connects to or the network card in your computer? As the MAC address of your network card can be found out with similar code to this...
            public static NICInfo GetNICInfo()
                const String NO_MAC_ADDRESS = "00:00:00:00:00:00";
                NICInfo nicInfo = null;
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                    if (Convert.ToBoolean(mo["IPEnabled"]))
                        if (!mo["MacAddress"].ToString().Equals(NO_MAC_ADDRESS))
                            nicInfo = new NICInfo(mo["MacAddress"].ToString(), mo["DNSHostName"].ToString());
                if (nicInfo == null)
                    nicInfo = new NICInfo(NO_MAC_ADDRESS, Environment.MachineName);
                return nicInfo;
    You will have to add a reference to 'System.Management' into the same project.

    Note: NICInfo is just a struct to hold a Machine name and MAC address pair.
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)