IP addresses

  • Thread starter Thread starter Mystique
  • Start date Start date
M

Mystique

Hi,
I have an application that needs to change the IP address of the local
computer.
How can I do this?

Regards,
Mystique
 
Mystique,

You will want to use the classes in the System.Management namespace to
get the instance of the Win32_NetworkAdapterConfiguration WMI class that
corresponds to the adapter. Once you have that, you can call the
EnableStatic method on the instance to set the IP address for the adapter.

Hope this helps.
 
Ok,
And how can make the application Obtain an IP automatically?

Nicholas Paldino said:
Mystique,

You will want to use the classes in the System.Management namespace to
get the instance of the Win32_NetworkAdapterConfiguration WMI class that
corresponds to the adapter. Once you have that, you can call the
EnableStatic method on the instance to set the IP address for the adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mystique said:
Hi,
I have an application that needs to change the IP address of the local
computer.
How can I do this?

Regards,
Mystique
 
Hi Mystique

Maybe you find the code below useful. It shows your IP-address. I didn't try
EnableStatic because I didn't find it practical to run the risk corrupting
my machine...

Christiaan.



ManagementClass mc = new
ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
Console.WriteLine("Description: {0}", mo["Description"].ToString());
if((bool)mo["IPEnabled"] == true)
{

string[] IPAddresses=(string[]) mo["IPAddress"];
for (int i=0;i<IPAddresses.Length;i++)
{
Console.WriteLine("+-> IpAddress {0} is:
{1}.",i.ToString(),IPAddresses);
}

Console.WriteLine("+-> MAC address: {0}", mo["MacAddress"].ToString());
}
mo.Dispose();
}



Nicholas Paldino said:
Mystique,

You will want to use the classes in the System.Management namespace to
get the instance of the Win32_NetworkAdapterConfiguration WMI class that
corresponds to the adapter. Once you have that, you can call the
EnableStatic method on the instance to set the IP address for the adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mystique said:
Hi,
I have an application that needs to change the IP address of the local
computer.
How can I do this?

Regards,
Mystique
 
thanks Christiaan
I figured that out
But can u tell me how i can make the OS to get automatically IPs from the
DNS server?

Regards,
Mystique

Christiaan Nijdam said:
Hi Mystique

Maybe you find the code below useful. It shows your IP-address. I didn't try
EnableStatic because I didn't find it practical to run the risk corrupting
my machine...

Christiaan.



ManagementClass mc = new
ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
Console.WriteLine("Description: {0}", mo["Description"].ToString());
if((bool)mo["IPEnabled"] == true)
{

string[] IPAddresses=(string[]) mo["IPAddress"];
for (int i=0;i<IPAddresses.Length;i++)
{
Console.WriteLine("+-> IpAddress {0} is:
{1}.",i.ToString(),IPAddresses);
}

Console.WriteLine("+-> MAC address: {0}", mo["MacAddress"].ToString());
}
mo.Dispose();
}



message news:[email protected]...
Mystique,

You will want to use the classes in the System.Management namespace to
get the instance of the Win32_NetworkAdapterConfiguration WMI class that
corresponds to the adapter. Once you have that, you can call the
EnableStatic method on the instance to set the IP address for the adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mystique said:
Hi,
I have an application that needs to change the IP address of the local
computer.
How can I do this?

Regards,
Mystique
 
If an address is not static, it comes from a DHCP server on your network,
not from a DNS server. Calling EnableDHCP() on the network adapter will
probably do what you want. I didn't try it myself.

See: ms-help://MS.VSCC/MS.MSDNVS/wmisdk/r_32hard4_6oq6.htm




Mystique said:
thanks Christiaan
I figured that out
But can u tell me how i can make the OS to get automatically IPs from the
DNS server?

Regards,
Mystique

Christiaan Nijdam said:
Hi Mystique

Maybe you find the code below useful. It shows your IP-address. I didn't try
EnableStatic because I didn't find it practical to run the risk corrupting
my machine...

Christiaan.



ManagementClass mc = new
ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
Console.WriteLine("Description: {0}", mo["Description"].ToString());
if((bool)mo["IPEnabled"] == true)
{

string[] IPAddresses=(string[]) mo["IPAddress"];
for (int i=0;i<IPAddresses.Length;i++)
{
Console.WriteLine("+-> IpAddress {0} is:
{1}.",i.ToString(),IPAddresses);
}

Console.WriteLine("+-> MAC address: {0}", mo["MacAddress"].ToString());
}
mo.Dispose();
}



message news:[email protected]...
Mystique,

You will want to use the classes in the System.Management
namespace
to
get the instance of the Win32_NetworkAdapterConfiguration WMI class that
corresponds to the adapter. Once you have that, you can call the
EnableStatic method on the instance to set the IP address for the adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,
I have an application that needs to change the IP address of the local
computer.
How can I do this?

Regards,
Mystique
 
Back
Top