Skip to content

Instantly share code, notes, and snippets.

@Kanst
Created October 31, 2013 16:11
Show Gist options
  • Save Kanst/7252403 to your computer and use it in GitHub Desktop.
Save Kanst/7252403 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#! -*- coding: utf-8 -*-
import re
f = open("access.log", "r")
text = f.read()
f.close()
ipv6_find = re.compile('(^|\n)' +\
'(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|' +\
'([0-9a-fA-F]{1,4}:){1,7}:|' +\
'([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}' +\
'|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|' +\
'([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|' +\
'([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|' +\
'([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|' +\
'[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|' +\
':((:[0-9a-fA-F]{1,4}){1,7}|:)) ')
count_ipv6 = len(re.findall(ipv6_find, text))
f = open("output.txt", "w")
text = f.write(str(count_ipv6))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment