2

This code gives MAC address of my PC but I want to find the MAC addresses of those mobile or computer devices who are connected to my wifi hotspot.

string mac = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{

    if (nic.OperationalStatus == OperationalStatus.Up &&
       (!nic.Description.Contains("Virtual") && !nic.Description.Contains("Pseudo")))
    {
        if (nic.GetPhysicalAddress().ToString() != "")
        {
            mac = nic.GetPhysicalAddress().ToString();
        }
    }
}
MessageBox.Show(mac);

I want to do something similar, like perhaps the following pseudo-code:

string MAC;
//method for retrieving mac address of the connected devices to my hotspot. 

ConnectedDevices() 
{
    // some code which will give you MAC of that device.
    MAC = mac address of connected device;
}
label1.text=mac.toString();

Thanks!

John Hascall
  • 9,176
  • 6
  • 48
  • 72
  • 1
    Define "my wifi hotspot". Do you share your internet connection from your PC's wired adapter through its WiFi-adapter, or do you want to get the client list from your physical access point, a device separate from your PC? – CodeCaster Jan 29 '16 at 19:11
  • I have portable wifi adapter and I plug it in my desktop and for creating hotspot I use cmd trick. – Code enthusiast Jan 30 '16 at 04:07

3 Answers3

1

At a first approximation you need an ARP cache viewer (try to execute "arp -a" and see if it's what you want.).

Please see this question.

Community
  • 1
  • 1
enkryptor
  • 1,574
  • 1
  • 17
  • 27
1

You can run netsh wlan show hosted from your code and parse the output. netsh wlan show hosted will give you the number of connected devices to your Hotspot and the MAC address of each one:

enter image description here

Andres
  • 6,080
  • 13
  • 60
  • 110
0

Some thoughts on this:

  1. Scrape the ip addresses from your hotspot's interface. Mine has telnet, ssh and web interfaces, so I can get the IP and MAC from that.

  2. Use the ARP table from the hotspot - it will contain IP/MAC as well.

  3. Use ARP on the subnet (if you are lucky enough to have subnetted hotspot traffic)

For processing ARP data here here is someone processing the output of the command and a post offering VB code to access the list directly, which can be translated. http://blog.laplante.io/2011/11/reading-arp-entries-with-c/

In past experience with this, I have had to broadcast ping the network in order to see all the devices. e.g. ping 192.168.1.255 (to ping the class C 192.168.1.*) - many ways of doing this here: Send a ping to each IP on a subnet this forces the address to be registered in arp.

Of course you will need to filter the ARP data to the specific data you are looking for from the hotspot because if you run this on a server or on your local machine is everything on the LAN, which isn't necessarily everything on the hotspot, so you would want to write something to get the data from the hotspot specifically.

Community
  • 1
  • 1
Brian C
  • 134
  • 4
  • you have shown how to get MAC of broadcasted devices. but I want MAC of those people who connected to my hotspot. – Code enthusiast Jan 30 '16 at 04:30
  • I saw from a comment above you are running the hotspot on your computer. Are the connections running on a separate network or are you providing NAT? If so, just filter the list of results of the ARP query by that network and you will have your MACs - ARP must know about these devices to relay traffic for them. If your computer is running as a bridge for this connection, it might be harder to pick them out. – Brian C Feb 01 '16 at 16:16