using System; using System.Management; namespace ArLi.CommonPrj {public class ChangeIP {/// /// Build of ArLi 2003.6.3 /// summary> public static readonly System.Version myVersion = new System. Version (1,1); private ManagementBaseObject iObj = null; private ManagementBaseObject oObj = null; private ManagementClass mc = new ManagementClass ( "Win32_NetworkAdapterConfiguration"); private readonly ManagementObjectCollection moc; /// /// Example: /// /// arli.commonprj.changeip o = new arli.commonprj.changeip (); /// String [] iplist = new string [] {"192.168.0.253", "192.168.0.250"}; // / String [] SUBNETLIST = new string [] "255.255.255.0", "255.255.255.0"}; /// o.changeto (iPlist, subnetList); /// code> /// summary> Public change () {moc = mc.getinstances ();} /// Control connection summary> /// IP address list param> /// Correspondence subnet mask list param> public void channelo (String [] ipaddr, string [] subnetmask {FOREACH ( ManagementObject Mo in moc) {if (! "" IPenabled "]) Continue; IOBJ = Mo.getMethodParameters (" enablestatic "); IOBJ [ipaddress"] = ipaddr; IOBJ ["SubnetMask"] = SubnetMask; OOBJ = Mo.invokeMethod ("EnableStatic", IObj, null;}} /// Control connection summary> /// IP address list param> ////////// Corresponding subnet mask list param> /// gateway list param> /// <
param name = "gatewayCostMetric"> metric listing gateway interface param> public void ChangeTo (string [] ipAddr, string [] subnetMask, string [] gateways, string [] gatewayCostMetric) {foreach (ManagementObject mo in moc) {if (! (BOOL) MO ["iPenabled"]) Continue; IOBJ = Mo.getMethodParameters ("enablestatic"); IOBJ [ipaddress "] = ipaddr; IOBJ [" SubnetMask "] = SubnetMask; Oobj = Mo.invokeMethod (" EnableStatic ", iObj, null); iObj = mo.GetMethodParameters (" SetGateways "); iObj [" DefaultIPGateway "] = gateways; iObj [" GatewayCostMetric "] = gatewayCostMetric; oObj = mo.InvokeMethod (" SetGateways ", iObj, null );}} /// Control connection summary> /// IP address list param> /// corresponding subnet mask Listing param> /// Gateway list param> /// Gateway interface hop number list param> /// DNS server list param> public void channelo (String [] ipaddr, string [] subnetMask, string [] Gateways, String [] GatewayCostMetric, String [] DNSServer ) {IF (! (Boxenable) mo ["iPenabled"]) Continue; IOBJ = Mo.getMethodParameters ("enablestatic"); IOBJ [ipaddress "] = ipaddr; IOBJ [" SubnetMask " ] = subnetMask; oObj = mo.InvokeMethod ( "EnableStatic", iObj, null); iObj = mo.GetMethodParameters ( "SetGateways"); iObj [ "DefaultIPGateway"] = gateways; iObj [ "gatewayCostMetric"] = gatewayCostMetric;