private static bool AllowDynamicPortsTraffic(string protocol, int startPort, int endPort) { string firewallRuleName = string.Format( CultureInfo.InvariantCulture, "Windows Fabric Dynamic Ports - {0} ({1})", protocol, RoleEnvironment.CurrentRoleInstance.Id); string deleteExistingRule = string.Format( CultureInfo.InvariantCulture, "advfirewall firewall delete rule name=\"{0}\"", firewallRuleName); string addAllowRule = string.Format( CultureInfo.InvariantCulture, "advfirewall firewall add rule name=\"{0}\" action=allow dir=in protocol={1} localport={2}-{3}", firewallRuleName, protocol, startPort, endPort); WindowsFabricAzureWrapperServiceCommon.ExecuteNetshCommand(deleteExistingRule); int exitCode = WindowsFabricAzureWrapperServiceCommon.ExecuteNetshCommand(addAllowRule); return(exitCode == 0); }
private static bool ReduceDynamicPortRange(int startPort, int portCount, string networkInterface, string transportProtocol) { int exitCode = WindowsFabricAzureWrapperServiceCommon.ExecuteNetshCommand( string.Format( CultureInfo.InvariantCulture, "int {0} set dynamicport {1} start={2} num={3}", networkInterface, transportProtocol, startPort, portCount)); return(exitCode == 0); }