MATLAB: Readind ip adress from text file

text file

How to read a packet ip addresses from text file and compare it with ip adresses used in firewall rules program?

Best Answer

This is slightly tricky as there are at least 5 valid formats for IP addresses, 4 of which are equivalent in representation power. In the more general case you may need to convert by value and "canonicalize" before doing the comparison (to the canonlicalized address in the firewall rules.)
The canonicalized format that is used for 32 bit IP addresses is the "dotted quad", regexp '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' where each of the digit groups is a decimal number from 0 to 255 with no leading zeros. But when users write addresses, they are allowed to use alternate formats, including leading zeros, and the values do not have to be in that range in some cases, and there might not be exactly 4 parts. 127.1 is a valid alternative for 127.0.0.1 for example.
So the first thing you have to do is figure out what input formats you are willing to deal with.