How can I test if two IPs are in the same network according to the subnet mask?

For example I have the IPs 1.2.3.4 and 1.2.4.3: Both are in the same network if the mask is 255.0.0.0 or 255.255.0.0 or even 255.255.248.0 but not if the mask is 255.255.255.0..

Edit
Report