Skip to content

Instantly share code, notes, and snippets.

@tuxnker
Last active February 27, 2016 09:56
Show Gist options
  • Select an option

  • Save tuxnker/89ff18d42e1f7dc8d520 to your computer and use it in GitHub Desktop.

Select an option

Save tuxnker/89ff18d42e1f7dc8d520 to your computer and use it in GitHub Desktop.
weblog_helper
#!//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