Getting mac address with CSharp

mac address with csharp

Image attribute: “MAC-48 Address” by Inductiveload, modified/corrected by Kju – SVG drawing based on PNG uploaded by User:Vtraveller. This can be found on Wikipedia here.. Licensed under CC BY-SA 2.5-2.0-1.0 via Commons.

Getting mac address with CSharp

Getting the mac address using CSharp development platform requires some skills that are specific to network programming aspects.

{Disclaimer: This work is not for hacking and troubling other users. Infact, it is a form of ethical hacking}

The term “white hat” in Internet slang refers to an ethical computer hacker, or a computer security expert, who specializes in penetration testing and in other testing methodologies to ensure the security of an organization’s information systems. Ethical hacking is a term coined by IBM meant to imply a broader category than just penetration testing. White-hat hackers may also work in teams called “sneakers”, red teams, or tiger teams.

Before starting our work, we need to applying core C# concepts.
All computers have MAC(Media Access Control)) addresses each one of it 6 Bytes of hexa decimal. You need to convert this from hex to a floating point, this can be done with the following equation: REDACTED

If you are running Windows XP or below, in a command prompt run the following:

> inject.library.dll 10.0.0.200 –windows /unix

On Windows 7 or Windows 7, the following can be used in Power Shell:

> velocity.inject:::DLL internet 10.0.0.200 (buffer overflow)

On Linux, the command is as follows:

for i > u ( inject.buffer command IP 10.0.0.200 )

These commands are used to inject modem and bring us the required information

Before starting the ethical hacking, we need some hacking tool such as ping, telnet, or ftp. You might need to try each tool because it depends on the operating system that his network is running. Generally, linksys network running cat5 are vulnerable to a ping attack, and netgear networks running cat6 are vulnerable to ftp attacks. Apple networks running wifi are vulnerable to telnet attacks.

Once you run your tools, you will be prompted to enter the memory offset to establish a connection. After you establish the connection, you will not have administrator access yet. You will need to send the terminal velocity that you identified earlier, and attach it to a neutral bogon assembly. This step can be tricky, but it’s often times easier to just type the velocity in notepad and paste it over and over into the victims modem.

If the velocity attack is successful, you will know. Your desktop and icons might change, and this is an indication that you are in their computer. DON’T WORRY. They can’t see what you are doing (this is the point of the memory buffer, remember). They see their windows, and you see yours. Once you are connected, you can browse their Facebook, play music through their speakers, and even start a fire by sending a bunch of sequential writes to their CPU.

Please note: This is provided that you are working in a test environment, or you are official sanctioned by the person or company to perform this penetration test. The rules and laws of your country apply, and I cannot be held responsible for the use of these hacking methods.
www.codeproject.com

/* complete credit to www.codeproject.com

struct IpToMacAddress

{

public IPAddress IpAddress

{ get { return m_IpAddress; } }

public byte[] MacAddress

{ get { return m_MacAddress; } }

public IpToMacAddress ( IPAddress ip, byte[] mac )

{

m_IpAddress = ip;

m_MacAddress = mac;

}

public override string ToString ()

{

return String.Format(“IP={0} MAC={1}”, m_IpAddress,

BitConverter.ToString(m_MacAddress));

}

private IPAddress m_IpAddress;

private byte[] m_MacAddress;

}

class Arp

{

public static IpToMacAddress[] GetArpTable ()

{

IntPtr pBuffer = IntPtr.Zero;

try

{

//Get the required size of the buffer

int size = 0;

GetIpNetTable(IntPtr.Zero, ref size, false);

//Allocate

pBuffer = Marshal.AllocHGlobal(size);

int result = GetIpNetTable(pBuffer, ref size, false);

//Enumerate the results

MIB_IPNETTABLE table = (MIB_IPNETTABLE)Marshal.PtrToStructure(pBuffer,

typeof(MIB_IPNETTABLE));

IpToMacAddress[] arr = new IpToMacAddress[table.dwNumEntries];

//Get the offset to the rows

IntPtr pTableOfs = (IntPtr)(pBuffer.ToInt64() + Marshal.OffsetOf(

typeof(MIB_IPNETTABLE), “table”).ToInt64());

int rowSize = Marshal.SizeOf(typeof(MIB_IPNETROW));

for (int nIdx = 0; nIdx < table.dwNumEntries; ++nIdx) { //Get the offset to the current row IntPtr pOfs = (IntPtr)(pTableOfs.ToInt64() + (rowSize * nIdx)); MIB_IPNETROW row = (MIB_IPNETROW)Marshal.PtrToStructure(pOfs, typeof(MIB_IPNETROW)); //If valid if (row.dwType != 2) { IPAddress ip = new IPAddress(BitConverter.GetBytes(row.dwAddr)); byte[] mac = new byte[row.dwPhysAddrLen]; Array.Copy(row.bPhysAddr, mac, row.dwPhysAddrLen); arr[nIdx] = new IpToMacAddress(ip, mac); }; }; return arr; } finally { if (pBuffer != IntPtr.Zero) Marshal.FreeHGlobal(pBuffer); }; } [StructLayout(LayoutKind.Sequential)] private struct MIB_IPNETTABLE { public int dwNumEntries; //public MIB_IPNETROW[] table; public IntPtr table; } [StructLayout(LayoutKind.Sequential)] private struct MIB_IPNETROW { public int dwIndex; public int dwPhysAddrLen; [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)] public byte[] bPhysAddr; public int dwAddr; public int dwType; } [DllImport("iphlpapi.dll")] private static extern int GetIpNetTable ( IntPtr pIpNetTable, ref int pdwSize, [MarshalAs(UnmanagedType.Bool)] bool bOrder ); }

Syed Adeel Ahmed
Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Published by

Syed Adeel Ahmed

Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Leave a Reply