Odd problem InetAddress.isReachable ()

My job is developing software for network cameras for retail. One of the software packages that my team is developing is a web server that retrieves various reports created in HTML by the camera itself (which has its own built-in web server) and is stored on the camera. Then, our SOFTWARE WILL RECEIVE these reports from the camera and store them on a central web server.

While we are perfectly connecting the IP addresses of the cameras to our software, I am developing a simple Java class that will query the network and find all the cameras on the network.

The problem is that although it works very well on my PC and on my college computer, when we try to run it on a real web server that will host our software ... it works, but it says that everyone The subnet IP address is offline / unreachable EXCEPT for the IP gateway.

For example, if I started it from a PC or my colleague's PC, when connected to a closed local network, I get the following active IP addresses found along with a flag telling me whether his camera is or not. (the gateway is 192.168.0.1, the subnet mask is 255.255.255.0, which means the full range of 256 devices to look for)

IP:/192.168.0.1 Active:true Camera:false IP:/192.168.0.100 Active:true Camera:true <- this is camera 1 IP:/192.168.0.101 Active:true Camera:true <- this is camera 2 IP:/192.168.0.103 Active:true Camera:false <- my PC IP:/192.168.0.104 Active:true Camera:false <- this is our webserver 

But for some reason, when starting the same program from the web server PC, using the same JRE, I get only the found

 IP:/192.168.0.1 Active:true Camera:false 

Now, my code, instead of listing through each IP in order in the main stream, instead creates a separate stream for each IP address being checked and starts them at the same time (otherwise, it will take no more than 21 minutes to time out a list with a timeout 5000 ms / IP). The main thread then restarts these IP scan threads every 15 seconds again and again.

I checked that all threads terminate on all PCs, there are no exceptions. It is even verified that not one of the threads is stuck. Each stream takes from 500 to 5050 ms from start to finish, and those flows that have active IP processing before (> 5000 ms), so I know that it correctly waits for 5000 ms in the ipAddr.isReachable (5000) method.

My colleague and I are stupid at the moment, while it seems that these active IP addresses are excellent when launched on our PCs, but do not receive a response from the PC web server.

We excluded problems with the firewall, problems with access to the administrator, etc. The only difference is that our web server is Embedded Win XP, and our PCs are Windows 7.

It surpassed us. Any ideas why?

Below is the code that starts each IP stream:

 public void CheckIP() { new Thread() { @Override public void run() { try { isActive = ipAddr.isReachable(5000); if (isActive) { if (!isCamera) { isCamera = new IpHttpManager().GetResponse(ipAddr.toString()); } } else { isCamera = false; } } catch (Exception e) { e.printStackTrace(); } } }.start(); 

}

EDIT: Here is the code that builds each IP address to check after defining a range based on the gateway and subnet ...

 for(int i=subMin; i<=subMax; i++) { byte[] ip = new byte[] {(byte)oct[0],(byte)oct[1],(byte)oct[2],(byte)i}; try { scanners[subCount] = new IpScan(InetAddress.getByAddress(ip)); subCount++; } catch (UnknownHostException e) { e.printStackTrace(); }} 
+3
java multithreading networking
Sep 26 '13 at 22:16
source share
2 answers

Thanks to everyone, but I never found out and didn’t find out why this strange thing happened. Everything that I checked was not the reason, so this question can be closed.

In any case, I completely circumvented it. Instead of using InetAddress, I simply rode on a native basis and created my own ICMP ping class instead of JNA, calling the Windows libraries IPHLPAPI.DLL and WSOCK32.DLL. Here is what I used ...

 public interface InetAddr extends StdCallLibrary { InetAddr INSTANCE = (InetAddr) Native.loadLibrary("wsock32.dll", InetAddr.class); ULONG inet_addr(String cp); //in_addr creator. Creates the in_addr C struct used below } public interface IcmpEcho extends StdCallLibrary { IcmpEcho INSTANCE = (IcmpEcho) Native.loadLibrary("iphlpapi.dll", IcmpEcho.class); int IcmpSendEcho( HANDLE IcmpHandle, //Handle to the ICMP ULONG DestinationAddress, //Destination address, in the form of an in_addr C Struct defaulted to ULONG Pointer RequestData, //Pointer to the buffer where my Message to be sent is short RequestSize, //size of the above buffer. sizeof(Message) byte[] RequestOptions, //OPTIONAL!! Can set this to NULL Pointer ReplyBuffer, //Pointer to the buffer where the replied echo is written to int ReplySize, //size of the above buffer. Normally its set to the sizeof(ICMP_ECHO_REPLY), but arbitrarily set it to 256 bytes int Timeout); //time, as int, for timeout HANDLE IcmpCreateFile(); //win32 ICMP Handle creator boolean IcmpCloseHandle(HANDLE IcmpHandle); //win32 ICMP Handle destroyer } 

And then using them to create the next method ...

 public void SendReply(String ipAddress) { final IcmpEcho icmpecho = IcmpEcho.INSTANCE; final InetAddr inetAddr = InetAddr.INSTANCE; HANDLE icmpHandle = icmpecho.IcmpCreateFile(); byte[] message = new String("thisIsMyMessage!".toCharArray()).getBytes(); Memory messageData = new Memory(32); //In C/C++ this would be: void *messageData = (void*) malloc(message.length); messageData.write(0, message, 0, message.length); //but ignored the length and set it to 32 bytes instead for now Pointer requestData = messageData; Pointer replyBuffer = new Memory(256); replyBuffer.clear(256); // HERE IS THE NATIVE CALL!! reply = icmpecho.IcmpSendEcho(icmpHandle, inetAddr.inet_addr(ipAddress), requestData, (short) 32, null, replyBuffer, 256, timeout); // NATIVE CALL DONE, CHECK REPLY!! icmpecho.IcmpCloseHandle(icmpHandle); } public boolean IsReachable () { return (reply > 0); } 
+4
Oct 15 '13 at 14:26
source share

I assume that your iterative logic to determine a different ip address is based on a different configuration, so your computer retrieves all the addresses, but your web server does not.

Try adding debugging to the logic, where you create a list of ip addresses to check.

0
Sep 26 '13 at 22:31
source share



All Articles