' Demonstrates the core windows firewall commands Imports System.Threading Imports System.Diagnostics Module Module1 Sub Main() ' Load windows firewall module mn.StartFirewall() ' Output full information about firewall profile currently in use Dim cp As UInteger = mn.GetCurrentProfile() Console.WriteLine("FIREWALL INFORMATION") Console.WriteLine("Firewall enabled: " + mn.GetFirewallEnabled(cp).ToString()) Console.WriteLine("Exceptions allowed: " + mn.GetExceptionsAllowed(cp).ToString()) Console.WriteLine("Notifications enabled: " + mn.GetNotificationsEnabled(cp).ToString()) Console.WriteLine("Unicast responses to multicast broadcast enabled: " + mn.GetUnicastToMulticastEnabled(cp).ToString()) Console.WriteLine("Remote admin IP version: " + mn.GetRemoteAdminIPVersion(cp).ToString()) Console.WriteLine("Remote admin scope: " + mn.GetRemoteAdminScope(cp).ToString()) Console.WriteLine("Remote admin addresses: " + mn.GetRemoteAdminAddresses(cp).ToString()) Console.WriteLine("Remote admin enabled: " + mn.GetRemoteAdminEnabled(cp).ToString()) Console.WriteLine("ICMP allow outbound destination unreachable: " + mn.GetICMPAllowOutboundDestinationUnreachable(cp).ToString()) Console.WriteLine("ICMP allow redirect: " + mn.GetICMPAllowRedirect(cp).ToString()) Console.WriteLine("ICMP allow inbound echo request: " + mn.GetICMPAllowInboundEchoRequest(cp).ToString()) Console.WriteLine("ICMP allow outbound time exceeded: " + mn.GetICMPAllowOutboundTimeExceeded(cp).ToString()) Console.WriteLine("ICMP allow outbound parameter problem: " + mn.GetICMPAllowOutboundParameterProblem(cp).ToString()) Console.WriteLine("ICMP allow outbound source quench: " + mn.GetICMPAllowOutboundSourceQuench(cp).ToString()) Console.WriteLine("ICMP allow inbound router request: " + mn.GetICMPAllowInboundRouterRequest(cp).ToString()) Console.WriteLine("ICMP allow inbound timestamp request: " + mn.GetICMPAllowInboundTimestampRequest(cp).ToString()) Console.WriteLine("ICMP allow inbound mask request: " + mn.GetICMPAllowInboundMaskRequest(cp).ToString()) Console.WriteLine("ICMP allow outbound packet too big: " + mn.GetICMPAllowOutboundPacketTooBig(cp).ToString()) Console.WriteLine("Press any key to continue...") Console.ReadKey() Console.WriteLine() Console.WriteLine("SERVICES INFORMATION") Console.WriteLine(mn.GetServiceAmount(cp).ToString() + " services found") Console.WriteLine() For n = 0 To mn.GetServiceAmount(cp) - 1 Console.WriteLine("Service name: " + mn.GetServiceName(cp, n)) Console.WriteLine("Service type: " + mn.GetServiceType(cp, n).ToString()) Console.WriteLine("Service customized: " + mn.GetServiceCustomized(cp, n).ToString()) Console.WriteLine("Service IP version: " + mn.GetServiceIPVersion(cp, n).ToString()) Console.WriteLine("Service scope: " + mn.GetServiceScope(cp, n).ToString()) Console.WriteLine("Service remote addresses: " + mn.GetServiceRemoteAddresses(cp, n)) Console.WriteLine("Service enabled: " + mn.GetServiceEnabled(cp, n).ToString()) Console.WriteLine() Next n Console.WriteLine("Press any key to continue...") Console.ReadKey() Console.WriteLine("\n") Console.WriteLine("AUTHORIZED APPLICATION INFORMATION") Console.WriteLine(mn.GetApplicationAmount(cp).ToString() + " authorized applications found") For n = 0 To mn.GetApplicationAmount(cp) - 1 Console.WriteLine("Application name: " + mn.GetApplicationName(cp, n)) Console.WriteLine("Application file name: " + mn.GetApplicationFileName(cp, n)) Console.WriteLine("Application IP version: " + mn.GetApplicationIPVersion(cp, n).ToString()) Console.WriteLine("Application scope: " + mn.GetApplicationScope(cp, n).ToString()) Console.WriteLine("Application remote addresses: " + mn.GetApplicationRemoteAddresses(cp, n)) Console.WriteLine("Application enabled: " + mn.GetApplicationEnabled(cp, n).ToString()) Console.WriteLine() Next n Console.WriteLine("Press any key to continue...") Console.ReadKey() Console.WriteLine() Console.WriteLine() ' Turn firewall 'off and on' or 'on and off' Dim Seconds As Integer = 3 Dim FirewallEnabled As Boolean = Convert.ToBoolean(mn.GetFirewallEnabled(cp)) If (FirewallEnabled = True) Then Console.WriteLine("Your firewall is enabled, would you like to disable it for " + Seconds.ToString() + " seconds? (1 = Yes, 0 = No)") Else Console.WriteLine("Your firewall is disabled, would you like to enable it for " + Seconds.ToString() + " seconds? (1 = Yes, 0 = No)") End If retryChangeFirewall: Dim charKey As Char = Console.ReadKey().KeyChar Dim bDo As Boolean Select (charKey) Case ("1") bDo = True Case ("0") bDo = False Case Else GoTo retryChangeFirewall End Select ' Flip firewall enabled so that if it is enabled we disable it and visa versa Dim FlippedFirewallEnabled As Boolean If (FirewallEnabled = True) Then FlippedFirewallEnabled = False Else FlippedFirewallEnabled = True If bDo = True Then Console.WriteLine("Taking action...") mn.SetFirewallEnabled(cp, FlippedFirewallEnabled) Console.WriteLine("Waiting " + Seconds.ToString() + " seconds...") Dim ts As TimeSpan = New TimeSpan(0, 0, Seconds) Thread.Sleep(ts) Console.WriteLine("Reversing action...") mn.SetFirewallEnabled(cp, FirewallEnabled) Console.WriteLine("Action reversed") End If Console.WriteLine("Press any key to continue...") Console.ReadKey() Console.WriteLine() Console.WriteLine() ' Add application to windows firewall Dim FileName As String = Process.GetCurrentProcess().MainModule.FileName Console.WriteLine("Adding application to windows firewall...") mn.AddApplication(cp, "MikeNet windows firewall test", FileName, 2, 0, "*", False) ' Check that operation completed successfully If mn.ApplicationExist(cp, FileName) = 1 Then Console.WriteLine("Application added successfully") ' Remove application from windows firewall Console.WriteLine("Removing application from windows firewall") mn.DeleteApplicationA(cp, FileName) If (mn.ApplicationExist(cp, FileName) = 0) Then Console.WriteLine("Application removed successfully") Else Console.WriteLine("Application was not removed successfully") End If Else Console.WriteLine("Application was not added successfully") End If Console.WriteLine("Press any key to exit...") Console.ReadKey() ' Unload windows firewall module mn.FinishFirewall() End Sub End Module