public FirewallRule.Actions GetDefaultOutboundAction(FirewallRule.Profiles profileType) { if (NetFwPolicy.get_DefaultOutboundAction((NET_FW_PROFILE_TYPE2_)profileType) == NET_FW_ACTION_.NET_FW_ACTION_BLOCK) { return(FirewallRule.Actions.Block); } return(FirewallRule.Actions.Allow); }
public void SetDefaultOutboundAction(FirewallRule.Profiles profileType, FirewallRule.Actions Action) { NetFwPolicy.set_DefaultOutboundAction((NET_FW_PROFILE_TYPE2_)profileType, Action == FirewallRule.Actions.Block ? NET_FW_ACTION_.NET_FW_ACTION_BLOCK : NET_FW_ACTION_.NET_FW_ACTION_ALLOW); }
public void SetBlockAllInboundTraffic(FirewallRule.Profiles profileType, bool Block) { NetFwPolicy.set_BlockAllInboundTraffic((NET_FW_PROFILE_TYPE2_)profileType, Block); }
public bool GetBlockAllInboundTraffic(FirewallRule.Profiles profileType) { return(NetFwPolicy.get_BlockAllInboundTraffic((NET_FW_PROFILE_TYPE2_)profileType)); }
public void SetFirewallEnabled(FirewallRule.Profiles profileType, bool Enabled) { NetFwPolicy.set_FirewallEnabled((NET_FW_PROFILE_TYPE2_)profileType, Enabled); }
public bool GetFirewallEnabled(FirewallRule.Profiles profileType) { return(NetFwPolicy.get_FirewallEnabled((NET_FW_PROFILE_TYPE2_)profileType)); }
public bool UpdateNetworks() { // foreach (NetworkInterface adapter in Interfaces) // todo: get data rates etc... adapter.GetIPStatistics() if (!UpdateInterfaces) { return(false); } UpdateInterfaces = false; Dictionary <string, FirewallRule.Profiles> NetworkProfiles = new Dictionary <string, FirewallRule.Profiles>(); foreach (INetwork network in netMgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED).Cast <INetwork>()) { FirewallRule.Profiles FirewallProfile = FirewallRule.Profiles.Undefined; switch (network.GetCategory()) { case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PRIVATE: FirewallProfile = FirewallRule.Profiles.Private; break; case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PUBLIC: FirewallProfile = FirewallRule.Profiles.Public; break; case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED: FirewallProfile = FirewallRule.Profiles.Domain; break; } foreach (INetworkConnection connection in network.GetNetworkConnections().Cast <INetworkConnection>()) { string id = ("{" + connection.GetAdapterId().ToString() + "}").ToLower(); NetworkProfiles.Add(id, FirewallProfile); } } //DefaultProfile = App.engine.FirewallManager.GetCurrentProfiles(); AdapterInfoByIP.Clear(); //AppLog.Debug("ListingNetworks:"); Interfaces = NetworkInterface.GetAllNetworkInterfaces(); // this is a bit slow! foreach (NetworkInterface adapter in Interfaces) { try { //AppLog.Debug("{0} {1} {2} {3}", adapter.Description, adapter.Id, adapter.NetworkInterfaceType.ToString(), adapter.OperationalStatus.ToString()); string id = adapter.Id.ToLower(); AdapterInfo Info = new AdapterInfo(); if (!NetworkProfiles.TryGetValue(id, out Info.Profile)) { Info.Profile = DefaultProfile; } switch (adapter.NetworkInterfaceType) { case NetworkInterfaceType.Ethernet: case NetworkInterfaceType.GigabitEthernet: case NetworkInterfaceType.FastEthernetT: case NetworkInterfaceType.FastEthernetFx: case NetworkInterfaceType.Ethernet3Megabit: case NetworkInterfaceType.TokenRing: Info.Type = FirewallRule.Interfaces.Lan; break; case NetworkInterfaceType.Wireless80211: Info.Type = FirewallRule.Interfaces.Wireless; break; case NetworkInterfaceType.Ppp: Info.Type = FirewallRule.Interfaces.RemoteAccess; break; default: Info.Type = FirewallRule.Interfaces.All; break; } Info.Addresses = new List <UnicastIPAddressInformation>(); IPInterfaceProperties ip_info = adapter.GetIPProperties(); Info.GatewayAddresses = new List <IPAddress>(); foreach (var gw in ip_info.GatewayAddresses) { Info.GatewayAddresses.Add(gw.Address); } Info.DnsAddresses = ip_info.DnsAddresses; Info.DhcpServerAddresses = ip_info.DhcpServerAddresses; Info.WinsServersAddresses = ip_info.WinsServersAddresses; foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses) { Info.Addresses.Add(ip); // Sanitize IPv6 addresses IPAddress _ip = new IPAddress(ip.Address.GetAddressBytes()); //AppLog.Debug("{2}({5}) has IP {0}/{3}/{4} has profile {1}", ip.Address.ToString(), ((FirewallRule.Profiles)Info.Profile).ToString(), // adapter.Description, ip.IPv4Mask.ToString(), ip.PrefixLength.ToString(), adapter.NetworkInterfaceType.ToString()); if (!AdapterInfoByIP.ContainsKey(_ip)) { AdapterInfoByIP[_ip] = Info; } } } catch { } // in case a adapter becomes invalid justa fter the enumeration } //AppLog.Debug("+++"); NetworksChanged?.Invoke(this, new EventArgs()); return(true); }
public FirewallRule.Profiles DefaultProfile = FirewallRule.Profiles.Public; // default windows behavioure: default profile is public public void UpdateNetworks() { LastNetworkUpdate = MiscFunc.GetTickCount64(); Dictionary <string, FirewallRule.Profiles> NetworkProfiles = new Dictionary <string, FirewallRule.Profiles>(); foreach (INetwork network in netMgr.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED).Cast <INetwork>()) { FirewallRule.Profiles FirewallProfile = FirewallRule.Profiles.Undefined; switch (network.GetCategory()) { case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PRIVATE: FirewallProfile = FirewallRule.Profiles.Private; break; case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PUBLIC: FirewallProfile = FirewallRule.Profiles.Public; break; case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED: FirewallProfile = FirewallRule.Profiles.Domain; break; } foreach (INetworkConnection connection in network.GetNetworkConnections().Cast <INetworkConnection>()) { string id = ("{" + connection.GetAdapterId().ToString() + "}").ToLower(); NetworkProfiles.Add(id, FirewallProfile); } } //DefaultProfile = App.engine.FirewallManager.GetCurrentProfiles(); AdapterInfoByIP.Clear(); //AppLog.Debug("ListingNetworks:"); foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) // this is a bit slow! { string id = adapter.Id.ToLower(); AdapterInfo Info = new AdapterInfo(); if (!NetworkProfiles.TryGetValue(id, out Info.Profile)) { Info.Profile = DefaultProfile; } switch (adapter.NetworkInterfaceType) { case NetworkInterfaceType.Ethernet: case NetworkInterfaceType.GigabitEthernet: case NetworkInterfaceType.FastEthernetT: case NetworkInterfaceType.FastEthernetFx: case NetworkInterfaceType.Ethernet3Megabit: case NetworkInterfaceType.TokenRing: Info.Type = FirewallRule.Interfaces.Lan; break; case NetworkInterfaceType.Wireless80211: Info.Type = FirewallRule.Interfaces.Wireless; break; case NetworkInterfaceType.Ppp: Info.Type = FirewallRule.Interfaces.RemoteAccess; break; default: Info.Type = FirewallRule.Interfaces.All; break; } Info.Addresses = new List <UnicastIPAddressInformation>(); IPInterfaceProperties ip_info = adapter.GetIPProperties(); Info.GatewayAddresses = new List <IPAddress>(); foreach (var gw in ip_info.GatewayAddresses) { Info.GatewayAddresses.Add(gw.Address); } Info.DnsAddresses = ip_info.DnsAddresses; Info.DhcpServerAddresses = ip_info.DhcpServerAddresses; Info.WinsServersAddresses = ip_info.WinsServersAddresses; foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses) { Info.Addresses.Add(ip); // Sanitize IPv6 addresses IPAddress _ip = new IPAddress(ip.Address.GetAddressBytes()); //AppLog.Debug("{2}({5}) has IP {0}/{3}/{4} has profile {1}", ip.Address.ToString(), ((FirewallRule.Profiles)Info.Profile).ToString(), // adapter.Description, ip.IPv4Mask.ToString(), ip.PrefixLength.ToString(), adapter.NetworkInterfaceType.ToString()); if (!AdapterInfoByIP.ContainsKey(_ip)) { AdapterInfoByIP[_ip] = Info; } } } //AppLog.Debug("+++"); }