Last active
February 27, 2016 09:56
-
-
Save tuxnker/89ff18d42e1f7dc8d520 to your computer and use it in GitHub Desktop.
weblog_helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!//usr/bin/env python | |
| import re | |
| import sys | |
| import getopt | |
| from netaddr import IPNetwork | |
| def main(argv): | |
| ip = '' | |
| infile = '' | |
| try: | |
| opts, args = getopt.getopt(argv,"hi:f:",["ip=","infile="]) | |
| except getopt.GetoptError: | |
| print 'weblog_helper -ip <ipaddress> -f <infile>' | |
| sys.exit(2) | |
| for opt, arg in opts: | |
| if opt == '-h': | |
| print 'weblog_helper --ip <ipaddress> -f <infile>' | |
| sys.exit() | |
| elif opt in ("-i", "--ip"): | |
| ip = arg | |
| elif opt == "-f": | |
| infile = arg | |
| ip_cidr = IPNetwork(ip) | |
| for i in ip_cidr: | |
| for line in open(infile): | |
| if re.search('%s\s' %i, line): | |
| print line, | |
| if line == None: | |
| print 'no matches found' | |
| if __name__ == "__main__": | |
| main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment