Skip to content

Instantly share code, notes, and snippets.

@Karthikeyan298
Karthikeyan298 / cidr_to_regex.py
Created July 3, 2018 13:21 — forked from 112buddyd/cidr_to_regex.py
Python CIDR Notation to Regex Tool
def cidr_to_regex(cidr):
import re
# Validation
cidr_regex = r'^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}' \
'([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$'
if not re.match(cidr_regex, cidr):
return 'Input not valid CIDR notation. Ex. 192.168.1.0/24'
# Setup Regex string dictionary
map = {}