473,324 Members | 2,370 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,324 software developers and data experts.

Getting IP adapters list

In a sample code I do something like this:

//Populate IP List
IPHost=Dns.GetHostByName(Dns.GetHostName());
DefaultIPCombo.Items.Clear();
DefaultIPCombo.Items.Add(IPHost.AddressList[0].ToString());
DefaultIPCombo.SelectedIndex=0;

How can I get all the IP adapters since this does only give me the IP
address of the default adapter. I have a wireless connection also and
would like to populate the DefaultIPCombo with all my network IPs. Is
this possible under C# .NET? Changing the IP manually and using the
connection at a specific adapter is possible but now... how to get all
the IPs?

I don't get it.

Thank you very much.

Nov 17 '05 #1
2 7514
Try,
using System.Management;
..
..
..
using (ManagementObjectSearcher managementObjectSearcher = new
ManagementObjectSearcher("SELECT * From Win32_NetworkAdapterConfiguration
WHERE IPEnabled = 1"))
{
using (ManagementObjectCollection managementObjectCollection =
managementObjectSearcher.Get())
{
foreach (ManagementObject managementObject in managementObjectCollection)
{
string desc = string.Empty, ipAddress = string.Empty, subnetMask =
string.Empty, macAddress = string.empty;

try
{
desc = managementObject[ "Description" ].ToString();
}
catch{}

try
{
ipAddress = ((string[])managementObject[ "IPAddress" ])[ 0 ];
}
catch{}

try
{
subnetMask = ((string[])managementObject[ "IPSubnet" ])[ 0 ];
}
catch{}

try
{
macAddress = managementObject[ "MacAddress" ].ToString();
}
catch{}

managementObject.Dispose();
}
}
}

All the Best,
Phil.

"Nuno Magalhaes" wrote:
In a sample code I do something like this:

//Populate IP List
IPHost=Dns.GetHostByName(Dns.GetHostName());
DefaultIPCombo.Items.Clear();
DefaultIPCombo.Items.Add(IPHost.AddressList[0].ToString());
DefaultIPCombo.SelectedIndex=0;

How can I get all the IP adapters since this does only give me the IP
address of the default adapter. I have a wireless connection also and
would like to populate the DefaultIPCombo with all my network IPs. Is
this possible under C# .NET? Changing the IP manually and using the
connection at a specific adapter is possible but now... how to get all
the IPs?

I don't get it.

Thank you very much.

Nov 17 '05 #2
Thank you. It works like a charm now. I'm getting the list of all IPs
available and enabled correctly.

Phil Williams wrote:
Try,
using System.Management;
.
.
.
using (ManagementObjectSearcher managementObjectSearcher = new
ManagementObjectSearcher("SELECT * From Win32_NetworkAdapterConfiguration
WHERE IPEnabled = 1"))
{
using (ManagementObjectCollection managementObjectCollection =
managementObjectSearcher.Get())
{
foreach (ManagementObject managementObject in managementObjectCollection)
{
string desc = string.Empty, ipAddress = string.Empty, subnetMask =
string.Empty, macAddress = string.empty;

try
{
desc = managementObject[ "Description" ].ToString();
}
catch{}

try
{
ipAddress = ((string[])managementObject[ "IPAddress" ])[ 0 ];
}
catch{}

try
{
subnetMask = ((string[])managementObject[ "IPSubnet" ])[ 0 ];
}
catch{}

try
{
macAddress = managementObject[ "MacAddress" ].ToString();
}
catch{}

managementObject.Dispose();
}
}
}

All the Best,
Phil.

"Nuno Magalhaes" wrote:
In a sample code I do something like this:

//Populate IP List
IPHost=Dns.GetHostByName(Dns.GetHostName());
DefaultIPCombo.Items.Clear();
DefaultIPCombo.Items.Add(IPHost.AddressList[0].ToString());
DefaultIPCombo.SelectedIndex=0;

How can I get all the IP adapters since this does only give me the IP
address of the default adapter. I have a wireless connection also and
would like to populate the DefaultIPCombo with all my network IPs. Is
this possible under C# .NET? Changing the IP manually and using the
connection at a specific adapter is possible but now... how to get all
the IPs?

I don't get it.

Thank you very much.


Nov 17 '05 #3

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

Similar topics

2
by: tylerdurden | last post by:
Hi. I want to write application which 1) Get list of windows 2) Change activ window ad1 I have writen: Process localAll = Process.GetProcesses(); String lista = "Lista procesow\n"; for (int...
0
by: Nuno Magalhaes | last post by:
In a sample code I do something like this: //Populate IP List IPHost=Dns.GetHostByName(Dns.GetHostName()); DefaultIPCombo.Items.Clear(); DefaultIPCombo.Items.Add(IPHost.AddressList.ToString());...
6
by: JD | last post by:
Hi all, Can anyone tell me is there a way to get a list of file types either supported on the server or clients computer and bind it to a drop down list in C# Thanks Jonathan Dixon
0
by: Brian Henry | last post by:
I want to pull my contact list (personal one) from the exchange server into a local text file. I know how to write stuff into a text file, just getting it from an exchange server is my problem....
3
by: sundew | last post by:
so here is the test case: <head> <script type='text/javascript'> // this function simply returns the number of enumerable namespaces(objects) function numNSpaces(){ var num = 0; for(var i in...
1
by: Aleksey | last post by:
Hi, all! Is there any standard way to get list of all components on my win form, including components that their parent isn't form it self, but panel on the form? Or to get this list I need create...
2
by: Troels Arvin | last post by:
Hello, I need a way to list an instance's databases, in a way which is easy to parse (I can't count on perl or similar scripting tools to be available everywhere). I know of the 'db2 list...
6
by: nagar | last post by:
I need to get the list of Autocorrect entries in word. Is there a way to do it without connecting to Word? Is the list saved somewhere? If I need to connect to Word, how can I detect if it's...
2
by: swethak | last post by:
hi, i have to get the gmail contact list using jsp code. For that purpose i have to use the Google data Api <%@ page import="com.xdatasystem.contactsimporter.*" %> <% // automatically...
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...
0
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...
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: 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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: 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.