/// <summary> /// command specific implementation /// </summary> internal override void commandImplementation() { if (!this.isSerialClient) { Console.WriteLine("Command only supported in serial wcscli client mode"); return; } NetworkInterfaces.NetworkPropertiesResponse myResponse = new NetworkInterfaces.NetworkPropertiesResponse(); dynamic newIp = null; dynamic hostName = null; dynamic newSubnet = null; dynamic netMask = null; dynamic newGateway = null; dynamic primaryDNS = null; dynamic secondaryDNS = null; dynamic interfaceId = null; dynamic ipSource = null; try { this.argVal.TryGetValue('a', out ipSource); if (!this.argVal.TryGetValue('t', out interfaceId)) { interfaceId = 1; // set the default interface id as 1 } if (string.Equals((string)ipSource, "STATIC", StringComparison.OrdinalIgnoreCase)) { if ( this.argVal.TryGetValue('i', out newIp) && this.argVal.TryGetValue('p', out primaryDNS) && this.argVal.TryGetValue('d', out secondaryDNS) && this.argVal.TryGetValue('m', out netMask) ) { this.argVal.TryGetValue('s', out newSubnet); this.argVal.TryGetValue('g', out newGateway); this.argVal.TryGetValue('n', out hostName); } else { Console.WriteLine(WcsCliConstants.invalidCommandString); Console.WriteLine("All required parameters not supplied"); return; } } // Set network properties myResponse = NetworkInterfaces.SetNetworkProperties( (string)newIp, (string)hostName, (string)newSubnet, (string)netMask, (string)newGateway, (string)primaryDNS, (string) secondaryDNS, (string)ipSource, (int)interfaceId); } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } if (myResponse == null) { Console.WriteLine(WcsCliConstants.serviceResponseEmpty); return; } if (myResponse.completionCode == 1) { Console.WriteLine("Command succeeded with completion code: " + myResponse.completionCode); } else if (myResponse.completionCode == 0) { Console.WriteLine("Command failed with completion code: " + myResponse.completionCode); } }
/// <summary> /// command specific implementation /// </summary> internal override void commandImplementation() { if (!this.isSerialClient) { Console.WriteLine("Command only supported in serial WcsCli client mode."); return; } NetworkInterfaces.NetworkPropertiesResponse myResponse = new NetworkInterfaces.NetworkPropertiesResponse(); dynamic ipSource = null; dynamic newIp = null; dynamic netMask = null; dynamic primaryDNS = null; dynamic secondaryDNS = null; dynamic newGateway = null; dynamic interfaceId = null; try { // Get IP address source (static/DHCP) this.argVal.TryGetValue('a', out ipSource); if (string.Equals((string)ipSource, "STATIC", StringComparison.OrdinalIgnoreCase)) { if (this.argVal.TryGetValue('i', out newIp) && this.argVal.TryGetValue('m', out netMask)) { this.argVal.TryGetValue('p', out primaryDNS); this.argVal.TryGetValue('d', out secondaryDNS); this.argVal.TryGetValue('g', out newGateway); } else { Console.WriteLine(WcsCliConstants.invalidCommandString); Console.WriteLine(WcsCliConstants.commandFailure + " All required parameters not supplied"); return; } } // Get network interface ID if (!this.argVal.TryGetValue('t', out interfaceId)) { interfaceId = 0; // set the default network interface id as 0 } // Set network properties myResponse = NetworkInterfaces.SetNetworkProperties( (string)ipSource, (string)newIp, (string)netMask, (string)primaryDNS, (string)secondaryDNS, (string)newGateway, (uint)interfaceId); } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } // Always print out CLI command name and completion status so that // drivers that depend on parsing the text response can determine the // success or failure of the command if (myResponse == null) { Console.WriteLine(WcsCliConstants.serviceResponseEmpty); Console.WriteLine(WcsCliConstants.commandFailure + " wcscli -setnic: " + Contracts.CompletionCode.Failure); } else if (myResponse.completionCode == CompletionCode.Success) { Console.WriteLine(WcsCliConstants.commandSuccess + "wcscli -setnic: " + myResponse.completionCode); } else { Console.WriteLine(WcsCliConstants.commandFailure + " wcscli -setnic: " + myResponse.completionCode); } }
/// <summary> /// command specific implementation /// </summary> internal override void commandImplementation() { if (!this.isSerialClient) { Console.WriteLine("Command only supported in serial wcscli client mode.. Use native windows APIs for getting NIC info.."); return; } NetworkInterfaces.NetworkPropertiesResponse myResponse = new NetworkInterfaces.NetworkPropertiesResponse(); try { myResponse = NetworkInterfaces.GetNetworkProperties(); } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } if (myResponse == null) { Console.WriteLine(WcsCliConstants.serviceResponseEmpty); return; } uint index = 1; foreach (NetworkInterfaces.NetworkProperty res in myResponse.NetworkPropertyCollection) { if (res.completionCode == 1) { Console.WriteLine("N/w Interface {0}:", index); Console.WriteLine("\tIP Address\t\t: " + res.ipAddress); Console.WriteLine("\tHostname\t\t: " + res.dnsHostName); Console.WriteLine("\tMAC Address\t\t: " + res.macAddress); Console.WriteLine("\tSubnet Mask\t\t: " + res.subnetMask); Console.WriteLine("\tDHCP Enabled\t\t: " + res.dhcpEnabled.ToString()); Console.WriteLine("\tDHCP Server\t\t: " + res.dhcpServer); Console.WriteLine("\tDNS Domain\t\t: " + res.dnsDomain); Console.WriteLine("\tGateway Address\t\t: " + res.gatewayAddress); Console.WriteLine("\tPrimary\t\t\t: " + res.primary); Console.WriteLine("\tSecondary\t\t: " + res.secondary); Console.WriteLine("\tDNS Server\t\t: " + res.dnsAddress); Console.WriteLine("\tCompletion Code\t\t: " + res.completionCode); Console.WriteLine(); index++; } else if (res.completionCode == 0) { Console.WriteLine(WcsCliConstants.commandFailure); } else { Console.WriteLine("Command failed with completion code: {0}", res.completionCode.ToString()); } } }
/// <summary> /// command specific implementation /// </summary> internal override void commandImplementation() { if (!this.isSerialClient) { Console.WriteLine("Command only supported in serial WcsCli client mode. Use native windows APIs for getting NIC info."); return; } NetworkInterfaces.NetworkPropertiesResponse myResponse = new NetworkInterfaces.NetworkPropertiesResponse(); try { myResponse = NetworkInterfaces.GetNetworkProperties(); } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } // Always print out CLI command name and completion status so that // drivers that depend on parsing the text response can determine the // success or failure of the command if (myResponse == null) { Console.WriteLine(WcsCliConstants.serviceResponseEmpty); Console.WriteLine(WcsCliConstants.commandFailure + " wcscli -getnic: " + Contracts.CompletionCode.Failure); } else if (myResponse.completionCode != Contracts.CompletionCode.Success) { Console.WriteLine(WcsCliConstants.commandFailure + " wcscli -getnic: " + myResponse.completionCode); } else { Console.WriteLine(WcsCliConstants.commandSuccess); foreach (NetworkInterfaces.NetworkProperty res in myResponse.NetworkPropertyCollection) { if (res.completionCode == Contracts.CompletionCode.Success) { Console.WriteLine("N/W Interface {0}: ", Contracts.SharedFunc.NetworkCtrlPhysicalIndex((int)res.index)); Console.WriteLine("\tIndex\t\t\t: " + res.index); Console.WriteLine("\tDescription\t\t: " + res.description); Console.WriteLine("\tServiceName\t\t: " + res.serviceName); Console.WriteLine("\tMAC Address\t\t: " + res.macAddress); Console.WriteLine("\tIP Enabled\t\t: " + res.ipEnabled.ToString()); Console.WriteLine("\tDHCP Enabled\t\t: " + res.dhcpEnabled.ToString()); Console.WriteLine("\tDHCP Server\t\t: " + res.dhcpServer); Dictionary<string, string[]> netProp = new Dictionary<string, string[]>() {{"IP Address", res.ipAddress}, {"Subnet Mask", res.subnetMask}, {"Gateway Address", res.gatewayAddress}, {"DNS Servers", res.dnsSearchOrder}}; foreach (KeyValuePair<string, string[]> pair in netProp) { Console.Write("\t" + pair.Key + "\t\t:"); if (pair.Value != null) { Console.Write(" {"); for (int idx = 0; idx < pair.Value.Length; idx++) { Console.Write("{0}", pair.Value[idx]); if (idx < (pair.Value.Length - 1)) { Console.Write(", "); } } Console.Write("}"); } Console.WriteLine(""); } Console.WriteLine("\tDNS Hostname\t\t: " + res.dnsHostName); Console.WriteLine("\tDNS Domain\t\t: " + res.dnsDomain); Console.WriteLine("\tWINS Primary\t\t: " + res.winsPrimary); Console.WriteLine("\tWINS Secondary\t\t: " + res.winsSecondary); // Always print completion code as the last item since other drivers // use this to look for the complete set of information for one NIC Console.WriteLine("\tCompletion Code\t\t: " + res.completionCode); Console.WriteLine(); } } } Console.WriteLine("Completion Code: " + myResponse.completionCode); }