Getting adapter IP address....
I'm writing a small app that displays various computer info.
One of the sections is the network, I currently have it showing the adapter name, link status, mac address and speed.
What I want to do is show the ip address of the adapter as well, the problem is that the NetworkInformation class seems to provied everything but this...
I've tried the System.Net.IPHostEntry and retrived the IpAddressCollection but how do I identify which adapter has which IP address ?
Thanks in advance.
*edit: I'm using vs2005
Re: Getting adapter IP address....
there is some code on this page that shows how to change the IPAddy. Maybe you can tweak it to to get what you want....
kevin
Re: Getting adapter IP address....
Thanks, I'll have a look into that. I'd have hoped they just had a method that returned the ip address of the adapter but suppose you can't have everything :)
Re: Getting adapter IP address....
Hi
Here's something rough and ready for getting the information. This is a function I wrote that gets output from a command screen:
private string GetProcessString(string process, string args)
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.UseShellExecute = false;
psi.FileName = process;
psi.Arguments = args;
psi.RedirectStandardOutput = true;
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
string s = p.StandardOutput.ReadToEnd();
p.StandardOutput.Close();
return s;
}
Now call ipconfig from the command window:
GetProcessString("ipconfig", @"/all")
You'll get the output from ipconfig in a string. You can go through this, parsing out all of the details of the various network connections.
Hope this helps
Chris Seary
Re: Getting adapter IP address....
What about this? This gets the current active ip address.
VB Code:
Sub
Dim IpAddr As IPAddress() = ipEntry.AddressList
TextBox1.Text = " " + IpAddr(0).ToString()
End Sub
And the adapter info you can get from the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Adapters
Re: Getting adapter IP address....
I had addressed this a while ago in another thread that can get it using WMI. Check out the full example in post #6 of the thread below:
http://www.vbforums.com/showthread.php?t=397835
You can also check out the WMI codebank submission for some general ways of using it, as you can gather all sorts of system info.
<ADVERTISEMENT>MySystemSpy, also in my sig, was a prog that solely uses WMI to gather loads of info about the system, if you care to check it out (its freeeeee :) ) </ADVERTISEMENT>