1 /*
2 Copyright (C) 2000 - 2007 Grid Systems, S.A.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 /*
19 * Project: WindowsFirewallUtils
20 * Created on 03-ene-2005
21 *
22 * Copyright (c)2004 Grid Systems
23 */
24 package com.gridsystems.utils.windows;
25
26 /**
27 * Type description.
28 *
29 * @author <a href="mailto:rruiz@gridsystems.com">Rodrigo Ruiz Aguayo</a>
30 * @version 1.0
31 */
32 public class FirewallTester {
33 /**
34 * Main method.
35 *
36 * @param args Command line arguments
37 * @throws Exception If an error occurs
38 */
39 public static void main(String[] args) throws Exception {
40 System.out.println("Firewall present: " + Firewall.isPresent());
41 System.out.println("Firewall enabled: " + Firewall.isEnabled());
42
43 Firewall.setEnabled(false);
44 closePort(9110);
45 closePort(9116);
46 closePort(8000);
47 openPort("Servidor Omega", 9110);
48 openPort("Servidor Omega", 9116);
49 openPort("Servidor Omega", 8000);
50 Firewall.setEnabled(true);
51 }
52
53 /**
54 * Verbose open port.
55 *
56 * @param port The port number
57 * @throws FirewallException If an error occurs
58 */
59 private static void closePort(int port) throws FirewallException {
60 if (!Firewall.closePort(port)) {
61 System.out.println("Port " + port + " already closed");
62 }
63 }
64
65 /**
66 * Verbose open close.
67 *
68 * @param serviceName The service name
69 * @param port The port value
70 * @throws FirewallException If an error occurs
71 */
72 private static void openPort(String serviceName, int port) throws FirewallException {
73 if (!Firewall.openPort(serviceName, port)) {
74 System.out.println("Port " + port + " already open");
75 }
76 }
77 }