473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Getting MAC address/Physical IP address of machine through C#

Hi,

I need to get MAC address/physical ip address of machine. I am using
below code:

ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");
foreach (ManagementObject mo in mc.GetInstances())
{
string macAddr = mo["MACAddress"] as string;
if ( macAddr != null && macAddr.Trim() != "" )
return macAddr.ToString();
}

But this returns multiple IP addresses out of which Physical address
is shown twice and rest of the addresses I could not find in ipconfig/
all command output on cmd.

Could you help me understand the output?

I only want the physical address. IF there is any better alternative,
kindly let me know.

Thanks
Pioneer
Nov 10 '08 #1
1 7399
On Nov 10, 12:38*pm, Pioneer <adiid...@gmail.comwrote:
Hi,

I need to get MAC address/physical ip address of machine. I am using
below code:

ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");
foreach (ManagementObject mo in mc.GetInstances())
{
string macAddr = mo["MACAddress"] as string;
if ( macAddr != null && macAddr.Trim() != "" )
return macAddr.ToString();

}

But this returns multiple IP addresses out of which Physical address
is shown twice and rest of the addresses I could not find in ipconfig/
all command output on cmd.

Could you help me understand the output?

I only want the physical address. IF there is any better alternative,
kindly let me know.

Thanks
Pioneer
I'm not very sure but I think you will get one per device, either
physical or virtual (ie loopback). I'm sure there is a property that
indicate which kind of device you are dealing with.
Check the docs.
Nov 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
2
by: Michał Januszczyk | last post by:
Is there any _managed_ way of getting total physical memory installed in the machine Thanks in advanc Michał Januszczyk
7
by: MLH | last post by:
I would like to read a MAC address from at least one NIC in a PC on which I have an Access 97 runtime app installed. What's the least hassel method you know of?
4
by: nilesh | last post by:
Hello, I have a basic doubt. Consider following program : #include<stdio.h> int main() { int i, *ip; i = 10; ip = &i;
4
by: Verde | last post by:
I know this is somewhat OT, but don't know where else to ask: How can I discover the rough physical location of an IP address? By "rough physical location" I'm thinking at least country, and...
4
by: UJ | last post by:
Is there any way to find out the actual MAC Address that a request comes in from? We are trying to get a way where we can limit access to specific machines (TCP/IP isn't good enough - we want to do...
8
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there...
4
by: Macca | last post by:
Hi, I am using an asynchronous socket server to allow comms between multiple clients and my server. I know how to obtain the IPAddress of the client (network device) as shown below :- string...
3
by: elvira_wang | last post by:
heya, what sort of address is displayed when this instruction for instance is executed printf("myvar location is 0x%lx\n", (long) &myvar); is it logical address or linear address, i.e. with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.