Forums » .NET » .NET »

how can we get ip address, subnet mask , default gateway and dns server by c# code?


Posted Date: 15 Nov 2006      Posted By:: suneer     Member Level: Silver    Member Rank: 3555     Points: 2   Responses: 0



dear all

please tell me how can we get ipaddress, subnet mask, default gateway and dns server by c# code?

i have got a code with:
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();

string[] ipaddresses = (string[]) objMO["IPAddress"];
string[] subnets = (string[]) objMO["IPSubnet"];
string[] gateways = (string[]) objMO["DefaultIPGateway"];
string ipadr=ipaddresses[0].ToString();
string gate=gateways[0].ToString();
string snet=subnets[0].ToString();

but system.management namespace is working in windows 2000 operating system only ( am i right?) , it is giving error in XP.

please anybody give me the code .


thankzz in advanse
suneer




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Awards & Gifts
Talk to Webmaster Tony John

Online Members

Jacob Cole
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India