title: Get MAC address via TCPListener in C#
body: <p>Is it possible to get MAC Address of remote client  via TCPListener in C#?</p>
  
  <pre><code>using System;  
  using System.Net;  
  using System.Net.Sockets;  
  using System.IO;  
  using System.Text;  
  
  namespace TCPserver  
  {  
      class Program  
      {  
          private const int BUFSIZE = 32;  
  
          static void Main(string[] args)  
          {  
              if (args.Length &gt; 1) // Test for correct of args  
                  throw new ArgumentException("Parameters: [&lt;Port&gt;]");  
  
              int servPort = (args.Length == 1) ? Int32.Parse(args[0]) : 7;  
  
              TcpListener listener = null;  
  
              try  
              {  
                  // Create a TCPListener to accept client connections  
                  listener = new TcpListener(IPAddress.Any, servPort);  
                  listener.Start();  
              }  
              catch (SocketException se)  
              {  
                  Console.WriteLine(se.Message);  
                  Environment.Exit(se.ErrorCode);  
              }  
  
              byte[] rcvBuffer = new byte[BUFSIZE]; // Receive buffer  
              int bytesRcvd; // Received byte count  
  
              for (; ; )  
              { // Run forever, accepting and servicing connections  
  
                  TcpClient client = null;  
                  NetworkStream ns = null;  
                  try  
                  {  
                      client = listener.AcceptTcpClient(); // Get client connection  
                      ns = client.GetStream();  
                      Console.Write("Handling client - ");  
  
                      // Receive until client closes connection  
                      int totalBytesEchoed = 0;  
                      while ((bytesRcvd = ns.Read(rcvBuffer, 0, rcvBuffer.Length)) &gt; 0)  
                      {  
                          ns.Write(rcvBuffer, 0, bytesRcvd);  
                          totalBytesEchoed += bytesRcvd;  
                      }  
                      Console.WriteLine("echoed {0} bytes.", totalBytesEchoed);  
  
                      ns.Close();  
                      client.Close();  
  
                  }  
                  catch (Exception e)  
                  {  
                      Console.WriteLine(e.Message);  
                      ns.Close();  
                  }  
              }  
          }  
      }  
  }  
  </code></pre>