Tuesday, April 24, 2007

Java: IP Analyzer

In my current position at work I help with some of our institutional customers who access our online application. In order to verify that a customer should have access we obtain their external IPs and keep them on file. The IPs used must be unique to the institution in question and cannot be gateways for location areas larger than what is on the contract. Unfortunately what happens is that we are given IP lists that are gateways by accident and since we aren't aware of this fact those IPs become active. Eventually we come to realize what happened and obtain a correct IP list from the customer.

Our problem comes from the fact that sometimes we are given the same gateway IPs from different customers and each time we go through the same difficulty when the IPs are activated. To avoid this a Microsoft Excel spreadsheet was created that listed all of the IPs we know to be gateway IPs and before we add anything to an account they are compared to this list. Unfortunately this list is rather cumbersome so I developed a java program that would do the same thing but be easy enough for the account managers to utilize without problem.

Like all of my current programs this one is fairly basic in setup, but then again it has a simple function and therefore does not need to be more intricate anyway. The program accesses a text file on the hard drive that lists all of the IPs on the "restricted" list and this can either be added to or searched on to see if a particular IP or IP range appears on this list. When adding an IP to the list the input from the user is simply append to the end of the text document. Searching on this for a comparison is a little more difficult. The current list of "restricted" IPs are converted into an array of single IPs. Then the IP given by the user to search with is also converted into an array of IPs. Once these two steps are completed the arrays are compared and if any of the IPs are found to be present in both arrays an error message is displayed to the user with the IP in question displayed.

Obviously this is a brute strength approach to comparing the IPs and as a result has its problems. First, any IP ranges of Class B or A cannot be used as they crash the program due to the memory requirements. Thankfully this does not come up often and therefore hasn't been encountered yet. However I'd like to add internal IP ranges to this program as part of the "restricted" list but I can't do this as 10.*.*.* is internal and would crash the program every time. Secondly, IPs must be entered in an exact format or they will not be recognized by the program and the comparison will not function correctly. IPs must be entered in the four octet format with no spaces and a dash between the start and end of the IP range, such as 52.52.52.52-52.52.52.178.

Overall the program works quite well for the purpose intended. If the document containing the "restricted" list was something other than a text file, such as a database or spreadsheet, then the searching algorithm may not be quite as memory intensive. However for the purpose intended such a change is not worth the effort.

No comments: