EDN Admin
Well-known member
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt Hello,
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt How does one relate a network interface adapter provided by the NetworkInterface class:
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt <span style=" http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface(VS.85).aspx
<span style="
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt to one provided by the <span style="color:black Win32_NetworkAdapterConfiguration management class:
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt I canât seem to find an index that can be related between the two.<span style="
Iâve tried looking at the âIndexâ and âInterfaceIndexâ in the management class, but they donât seem to relate to anything in the NetworkInterface class.
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt The reason for all this is that I would like adapt this piece of C# code into Visual C++ 2008, but set a static IP on only one NIC, designated by the user. That
is, in the code below, I need to select one and only one of the "management objects."
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<span style="font-family:"Courier New"; color:green; font-size:10pt
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; void setIP(<span style="color:Blue; string ip_address, <span style="color:Blue; string subnet_mask)
{
ManagementClass objMC = <span style="color:Blue; new ManagementClass(<span style="color:#A31515; "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
<span style="color:Blue; foreach (ManagementObject objMO <span style="color:Blue; in objMOC)
{
<span style="color:Blue; if ((<span style="color:Blue; bool)objMO[<span style="color:#A31515; "IPEnabled"])
{
<span style="color:Blue; try
{
ManagementBaseObject setIP;
ManagementBaseObject newIP =
objMO.GetMethodParameters(<span style="color:#A31515; "EnableStatic");
newIP[<span style="color:#A31515; "IPAddress"] = <span style="color:Blue; new <span style="color:Blue; string[] { ip_address };
newIP[<span style="color:#A31515; "SubnetMask"] = <span style="color:Blue; new <span style="color:Blue; string[] { subnet_mask };
setIP = objMO.InvokeMethod(<span style="color:#A31515; "EnableStatic", newIP, <span style="color:Blue; null);
}
<span style="color:Blue; catch (Exception)
{
<span style="color:Blue; throw;
}
}
}
}
[/code]
<p style="margin:0in 0in 0pt <br/>
<p style="margin:0in 0in 0pt <span style="font-family:"Courier New"; color:green; font-size:10pt <span style="color:#000000 <span style="font-family:Arial Thanks.
<p style="margin:0in 0in 0pt <span style="font-family:"Courier New"; color:green; font-size:10pt <span style="color:#000000 <span style="font-family:Arial <br/>
Brian
View the full article
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt How does one relate a network interface adapter provided by the NetworkInterface class:
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt <span style=" http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface(VS.85).aspx
<span style="
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; font-size:10pt to one provided by the <span style="color:black Win32_NetworkAdapterConfiguration management class:
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt I canât seem to find an index that can be related between the two.<span style="
Iâve tried looking at the âIndexâ and âInterfaceIndexâ in the management class, but they donât seem to relate to anything in the NetworkInterface class.
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt The reason for all this is that I would like adapt this piece of C# code into Visual C++ 2008, but set a static IP on only one NIC, designated by the user. That
is, in the code below, I need to select one and only one of the "management objects."
<p style="margin:0in 0in 0pt <span style="font-family:Arial; color:black; font-size:10pt
<span style="font-family:"Courier New"; color:green; font-size:10pt
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; void setIP(<span style="color:Blue; string ip_address, <span style="color:Blue; string subnet_mask)
{
ManagementClass objMC = <span style="color:Blue; new ManagementClass(<span style="color:#A31515; "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
<span style="color:Blue; foreach (ManagementObject objMO <span style="color:Blue; in objMOC)
{
<span style="color:Blue; if ((<span style="color:Blue; bool)objMO[<span style="color:#A31515; "IPEnabled"])
{
<span style="color:Blue; try
{
ManagementBaseObject setIP;
ManagementBaseObject newIP =
objMO.GetMethodParameters(<span style="color:#A31515; "EnableStatic");
newIP[<span style="color:#A31515; "IPAddress"] = <span style="color:Blue; new <span style="color:Blue; string[] { ip_address };
newIP[<span style="color:#A31515; "SubnetMask"] = <span style="color:Blue; new <span style="color:Blue; string[] { subnet_mask };
setIP = objMO.InvokeMethod(<span style="color:#A31515; "EnableStatic", newIP, <span style="color:Blue; null);
}
<span style="color:Blue; catch (Exception)
{
<span style="color:Blue; throw;
}
}
}
}
[/code]
<p style="margin:0in 0in 0pt <br/>
<p style="margin:0in 0in 0pt <span style="font-family:"Courier New"; color:green; font-size:10pt <span style="color:#000000 <span style="font-family:Arial Thanks.
<p style="margin:0in 0in 0pt <span style="font-family:"Courier New"; color:green; font-size:10pt <span style="color:#000000 <span style="font-family:Arial <br/>
Brian
View the full article