how to get IP address without using DNS

C

crespo

hi,Everybody.
I want to get my computer's local IP address,I search internet for some
help,but most of them suggests using DNS with
codes like these:
IPHostEntry ihe = Dns.GetHostByName(Dns.GetHostName());
IPAddress myself = ihe.AddressList[0];

But I don't want to use DNS,Could anyone help me? Any suggestions will be
really appreciated.

Best regards

Crespo

2006-06-18
 
N

Nicholas Paldino [.NET/C# MVP]

Crespo,

I would use the classes in the System.Management namespace to get the
information from the OS itself, not do a lookup.

You can look for instances of the Win32_NetworkAdapterConfiguration for
the network card you want to work with, and then get the IPAddress property
which is an array of the IP addresses that are associated with the network
adapter.

Hope this helps.
 
C

Crespo

Thank you,Nicholas Paldino.
I have tried your advice and it sucessfully works. Thanks again.

Crespo
"Nicholas Paldino [.NET/C# MVP]" <[email protected]> дÈëÏûÏ¢
Crespo,

I would use the classes in the System.Management namespace to get the
information from the OS itself, not do a lookup.

You can look for instances of the Win32_NetworkAdapterConfiguration for
the network card you want to work with, and then get the IPAddress property
which is an array of the IP addresses that are associated with the network
adapter.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top