0

I want to get an example or suggestion of how to use InetAddress in windows systems with firewall active. I don't know what is blocked by the firewall that isn't allowing this class in windows to work.

When I try to use this code in windows with firewall disabled I get the host name and isReachable to true:

InetAddress addrs = null;
try {
    addrs = InetAddress.getByName("192.168.1.1");
    System.out.println(addrs.getHostName());
    System.out.println(addrs.isReachable(100));
} catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

But activating firewall I get false, I can use policy for this?

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366

1 Answers1

2

You must configure the firewall to allow for the JVM (java.exe) to open connections. The java code does not need to change, it is a configuration issue.

SJuan76
  • 24,532
  • 6
  • 47
  • 87
  • Hello thanks, i allow java for in a out in my firewall but something is missing, my first println works now with the firewall on, but the second println return false, there is needed to allow something more for using ICMP or the port TCP 7 for isReachable method? – Diego Fernando Murillo Valenci Dec 18 '12 at 14:58
  • Which PC is `192.168.1.1`? Maybe it is your own machine? – SJuan76 Dec 18 '12 at 17:32
  • no, i am runing my program from an ubuntu (VMWare player) that have ip 192.168.1.5, that ip is my real machine that is windows 7 (192.168.1.1) from Ubuntu i can do ping and vice versa. – Diego Fernando Murillo Valenci Dec 18 '12 at 23:27
  • I take it you are connecting TO the windows machine that has firewall instead of FROM that machine? Still a configuration issue, allow for ICMP / ping messages in `192.168.1.1`. – SJuan76 Dec 19 '12 at 08:28