Skip to content

Instantly share code, notes, and snippets.

@jpbaudoin
Created May 30, 2022 20:23
Show Gist options
  • Save jpbaudoin/7d3f0cb3ada668962f9c48f9401283d8 to your computer and use it in GitHub Desktop.
Save jpbaudoin/7d3f0cb3ada668962f9c48f9401283d8 to your computer and use it in GitHub Desktop.
_Network
import ipaddress
import argparse
def check_ip_in_crd(ip, cidr):
return ipaddress.ip_address(ip) in ipaddress.ip_network(cidr)
parser = argparse.ArgumentParser(description='Check if IP is CIRD.')
parser.add_argument('IP', type=str,
help='IP to check')
parser.add_argument('CIRD', type=str,
help='CIRD where to check if the IP is.')
args = parser.parse_args()
IP = args.IP
CIRD = args.CIRD
print(check_ip_in_crd(IP, CIRD))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment