I am trying to create tool so IT applications owners can check a list of firewall interface ranges to see if the IP in behind a firewall before opening a firewall ticket for no reason. This list is about 500 IPs in the actually code.
If the the ip_check does come back True the response is easy and clean. With it enumerating through all the inter_list is returns a lot of false responses. I want to improve my logic so that the user get a yes its behind a firewall or no it is not behind a firewall. I am stuck and have been searching for a better way of doing this. I plan on this being a flask app.
import ipaddress as ip
Inter_List = ['192.168.1.1/24', '192.168.2.1/24', '192.168.3.1./24']
ip_input = input("Enter IP address:")
print("You entered this IP address:{}".format(ip_input))
for intaddr in Inter_List:
ip_check = ip.IPv4Address(ip_input) in ip.IPv4Network(intaddr, False)
if ip_check == True:
print('IP {} is in {} interface range is behind a firewall'.format(ip_input,intaddr))
else:
print("Not behind a firewall")