def add_rule(name, localport, protocol='tcp', action='allow', dir='in', remoteip='any'):
 cmd = ['netsh', 'advfirewall', 'firewall', 'add', 'rule', 'name={0}'.format(name), 'protocol={0}'.format(protocol), 'dir={0}'.format(dir), 'action={0}'.format(action), 'remoteip={0}'.format(remoteip)]
 if (('icmpv4' not in protocol) and ('icmpv6' not in protocol)):
  cmd.append('localport={0}'.format(localport))
 ret = __salt__['cmd.run'](cmd, python_shell=False)
 if isinstance(ret, six.string_types):
  return (ret.strip() == 'Ok.')
 else:
  log.error('firewall.add_rule failed: {0}'.format(ret))
  return False

def add_rule ( name , localport , protocol = 'tcp' , action = 'allow' , dir = 'in' , remoteip = 'any' ) : cmd = [ 'netsh' , 'advfirewall' , 'firewall' , 'add' , 'rule' , 'name={0}' . format ( name ) , 'protocol={0}' . format ( protocol ) , 'dir={0}' . format ( dir ) , 'action={0}' . format ( action ) , 'remoteip={0}' . format ( remoteip ) ] if ( ( 'icmpv4' not in protocol ) and ( 'icmpv6' not in protocol ) ) : cmd . append ( 'localport={0}' . format ( localport ) ) ret = __salt__ [ 'cmd.run' ] ( cmd , python_shell = False ) if isinstance ( ret , six . string_types ) : return ( ret . strip ( ) == 'Ok.' ) else : log . error ( 'firewall.add_rule failed: {0}' . format ( ret ) ) return False
add a new firewall rule .