TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ashutosh Tripathi
NA
44
11.6k
How to access the MAC address of the system?
Aug 25 2015 12:56 PM
How to access the MAC address of the system?
I have a code which is working fine but only on localhost. After publishing my website on server, it cannot access the MAC Address and either throw an exception
object reference not set to an instance of an object
or after using try catch it move to catch block.
I am providing my code, so that anyone can suggest me something fruitful:
public string GetMACAddress()
{
try
{
ManagementClass objMOS = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMOS.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject objMO in objMOC)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
MACAddress = objMO["MacAddress"].ToString();
}
objMO.Dispose();
}
MACAddress = MACAddress.Replace(":", "");
return MACAddress;
}
catch (Exception ei)
{
return "No Mac";
}
}
Reply
Answers (
9
)
Is lazy loading the default loading type in MVC?
mvc4 how to create download button