aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'modules/hosts/ipMatch.py')
-rw-r--r--modules/hosts/ipMatch.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/hosts/ipMatch.py b/modules/hosts/ipMatch.py
new file mode 100644
index 0000000..f633cd5
--- /dev/null
+++ b/modules/hosts/ipMatch.py
@@ -0,0 +1,15 @@
+import re
+
+def validate(userIn):
+ ipVer4 = "^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$"
+ ipVer6Std = "^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$"
+ ipVer6Hex = "^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$"
+
+ if(re.match(ipVer4, userIn)!=None):
+ return True
+ elif(re.match(ipVer6Std, userIn)!=None):
+ return True
+ elif(re.match(ipVer6Hex, userIn)!=None):
+ return True
+
+ return False