IT Community - Software Programming, Web Development and Technical Support

How to get the MAC Address By IP address in .net?

This is a discussion on How to get the MAC Address By IP address in .net? within the ASP and ASP.NET Programming forums, part of the Web Development category; How to get the MAC Address By IP address in .net?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-26-2007, 03:29 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Question How to get the MAC Address By IP address in .net?

How to get the MAC Address By IP address in .net?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-27-2007, 05:13 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to get the MAC Address By IP address in .net?

Hello Oxygen,

We can able to get the MAC address of a system in three ways programmatically.

Method One: UuidCreate
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[6];

UUID uuid;
UuidCreateSequential( &uuid ); // Ask OS to create UUID

for (int i=2; i<8; i++) // Bytes 2 through 7 inclusive
// are MAC address
MACData[i - 2] = uuid.Data4[i];

PrintMACaddress(MACData); // Print MAC address
}

Method Two: Use NetBIOS
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[8]; // Allocate data structure
// for MAC (6 bytes needed)

WKSTA_TRANSPORT_INFO_0 *pwkti; // Allocate data structure
// for NetBIOS
DWORD dwEntriesRead;
DWORD dwTotalEntries;
BYTE *pbBuffer;

// Get MAC address via NetBIOS's enumerate function
NET_API_STATUS dwStatus = NetWkstaTransportEnum(
NULL, // [in] server name
0, // [in] data structure to return
&pbBuffer, // [out] pointer to buffer
MAX_PREFERRED_LENGTH, // [in] maximum length
&dwEntriesRead, // [out] counter of elements
// actually enumerated
&dwTotalEntries, // [out] total number of elements
// that could be enumerated
NULL); // [in/out] resume handle
assert(dwStatus == NERR_Success);

pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer; // type cast the buffer

for(DWORD i=1; i< dwEntriesRead; i++) // first address is
// 00000000, skip it
{ // enumerate MACs & print
swscanf((wchar_t *)pwkti[i].wkti0_transport_address,
L"%2hx%2hx%2hx%2hx%2hx%2hx",
&MACData[0],
&MACData[1],
&MACData[2],
&MACData[3],
&MACData[4],
&MACData[5]);
PrintMACaddress(MACData);
}

// Release pbBuffer allocated by above function
dwStatus = NetApiBufferFree(pbBuffer);
assert(dwStatus == NERR_Success);
}

Method Three: Use GetAdaptersInfo

// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information
// for up to 16 NICs
DWORD dwBufLen = sizeof(AdapterInfo); // Save memory size of buffer

DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
AdapterInfo, // [out] buffer to receive data
&dwBufLen); // [in] size of receive data buffer
assert(dwStatus == ERROR_SUCCESS); // Verify return value is
// valid, no buffer overflow

PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
// current adapter info
do {
PrintMACaddress(pAdapterInfo->Address); // Print MAC address
pAdapterInfo = pAdapterInfo->Next; // Progress through
// linked list
}
while(pAdapterInfo); // Terminate if last adapter
}

For more Details: CodeGuru: Three ways to get your MAC address.


Hope this is Usefull to you.

The King Maker.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/2880-how-get-mac-address-ip-address-net.html
Posted By For Type Date
How to get the MAC Address By IP address in .net? | Web Hosting This thread Refback 10-05-2007 07:59 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Same IP Address vadivelanvaidyanathan Search Engine Optimization 0 01-23-2008 06:28 AM
Getting IP address with PHP sureshbabu PHP Programming 0 12-17-2007 07:01 AM
visitor's IP Address sivaramakrishnan PHP Programming 1 07-17-2007 08:01 AM
What is the significance of the IP address 255.255.255.255? Arun Server Management 0 07-17-2007 12:17 AM
IP address vadivelanvaidyanathan Server Management 0 07-15-2007 06:44 PM


All times are GMT -7. The time now is 03:21 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0