Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. MAC address code issue [modified]

MAC address code issue [modified]

Scheduled Pinned Locked Moved ASP.NET
csharphelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdul Rhman Alsri
    wrote on last edited by
    #1

    This code to find the MAC address of a PC connected to the internet. What's a sName in the code?

    public class GetMacAddressFromIPAddress
    {
    [DllImport("iphlpapi.dll", ExactSpelling=true)]
    public static extern int SendARP( int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen );
    public string GetMacAddress(string sName)
    {
    string s = string.Empty ;
    System.Net.IPHostEntry Tempaddr = null;
    Tempaddr = (System.Net.IPHostEntry)Dns.GetHostByName(sName);
    System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
    string[] Ipaddr = new string[3];
    foreach(IPAddress TempA in TempAd)
    {
    Ipaddr[1] = TempA.ToString();
    byte[] ab = new byte[6];
    int len = ab.Length;
    int r = SendARP( (int) TempA.Address, 0, ab, ref len );
    string sMAC = BitConverter.ToString( ab, 0, 6 );
    Ipaddr[2] = sMAC;
    s = sMAC;
    }
    return s;
    }
    }

    modified on Tuesday, May 25, 2010 4:01 AM

    L 1 Reply Last reply
    0
    • A Abdul Rhman Alsri

      This code to find the MAC address of a PC connected to the internet. What's a sName in the code?

      public class GetMacAddressFromIPAddress
      {
      [DllImport("iphlpapi.dll", ExactSpelling=true)]
      public static extern int SendARP( int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen );
      public string GetMacAddress(string sName)
      {
      string s = string.Empty ;
      System.Net.IPHostEntry Tempaddr = null;
      Tempaddr = (System.Net.IPHostEntry)Dns.GetHostByName(sName);
      System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
      string[] Ipaddr = new string[3];
      foreach(IPAddress TempA in TempAd)
      {
      Ipaddr[1] = TempA.ToString();
      byte[] ab = new byte[6];
      int len = ab.Length;
      int r = SendARP( (int) TempA.Address, 0, ab, ref len );
      string sMAC = BitConverter.ToString( ab, 0, 6 );
      Ipaddr[2] = sMAC;
      s = sMAC;
      }
      return s;
      }
      }

      modified on Tuesday, May 25, 2010 4:01 AM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      sName is IPAddress HTH

      Jinal Desai - LIVE Experience is mother of sage....

      A 1 Reply Last reply
      0
      • L Lost User

        sName is IPAddress HTH

        Jinal Desai - LIVE Experience is mother of sage....

        A Offline
        A Offline
        Abdul Rhman Alsri
        wrote on last edited by
        #3

        And this case , it's the internet ip address and not the pc ip address, isn't it? 2nd thing is that, when using this code, how to suppply internet address for it, do I have to get a code to detect the internet ip address and then pass it to the MAC Function? THanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups