Hi,
I am working on getting MAC address of a newly connected client using C#.
I have written server application and when client connects to my server, I want to get MAC addresses of clients and store it in database.
I could get IP address of client but could not find a way to get MAC address
Can anyone please help me?

Other thing that I am trying to do is shrink an image sent by a server to client. When an image is sent by server (picturebox in server is larger than that at client), client can not display it completely in its picturebox. I can see half image.
Is there any way I can shrink image sent by server?

Thanks

Recommended Answers

All 7 Replies

Refer these links.

PhysicalAddress Class
Get MAC address of client machine using C#

Also try this code snippet.

using System;
using System.Windows.Forms;
using System.Management; 
.
.
.

 private void button1_Click(object sender, EventArgs e)
        {
            ManagementObjectSearcher objQuery = null;
            ManagementObjectCollection queryCollection = null;

            try
            {
                objQuery = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");

                queryCollection = objQuery.Get();

                foreach (ManagementObject mgmtObject in queryCollection)
                {
                    if (mgmtObject["MacAddress"] != null)
                    {
                        MessageBox.Show(mgmtObject["MacAddress"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Source);
                MessageBox.Show(ex.Message);
            } 

        }

Are you running your software on both ends of the connection? MAC addresses are only "guaranteed valid" for layer 2 communications in a LAN. They do not traverse a router as you would think.

That being said if it is your software running on both ends then you can use the code Ramesh provided. If you just have an open socket then you can't reliably determine the remote MAC.

Thanks Ramesh.
I could use it to find a MAC address of local machine when local machine is a laptop or desktop.

But when I tried to do the same on PDA, I found that it does not have system.net.management and system.net.networkinterface namespace

Do you have any idea about how to get MAC addresses on PDA?

Thanks
Siddhesh

Hi Siddesh,

The System.Net.NetworkInformation will not be supported in Compact Framework.

You need to use OpenNETCF library to get the MAC address of a PDA.

The OpenNETCF.Net.NetworkInformation Namespace can have classes and methods to achieve this.

hi,
Got MAC address of PDA.
But now i get 2 mac addresses, both belong to same networktype "Ethernet".
If I see system configuration of WM, then I see one of the above physical addresses.
Which one does windows mobile use to send packets on network?
(one that is listed in system configuration or other physical address which is returned by opennetcf library functions?)

Thanks all.

Hi All,

Can someone help me out in getting client mac address by using java

Thanks in advance

You ask for Java and tag with C#
Which is it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.