> 
> **Possible Duplicate:**  
> 
> [How can I check if an ip is in a network in python](https://stackoverflow.com/questions/819355/how-can-i-check-if-an-ip-is-in-a-network-in-python) 
> 
> 
> 

I have one destination ip address from a file suppose `ip1 = 172.16.0.34`; and I have one more file having (subnet, mask, next-hop) i.e `172.16.0.0`, `255.255.255.0`, `117.120.10.1`

I have to check whether the incoming address ip1 matches the subnet entry for a particular route,after being ANDed with the netmask of that entry in the routing table. If the destination matches under mask,add the route to the list of feasible routes for this packet