Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import re
- import argparse
- def parse_args():
- parser = argparse.ArgumentParser()
- parser.add_argument("--all", help="show for all ips", action="store_true")
- parser.add_argument("logfile", help="squid access log file", action="store_true")
- parser.add_argument("iplist", help="list of ip addresses", action="store_true")
- return parser.parse_args()
- def main():
- args = parse_args()
- if args.all:
- outfile = "sites.txt"
- else:
- outfile = "sites_alarmers.txt"
- sites =[]
- log = open(args.logfile, 'r')
- ips = get_alarmers(args.iplist)
- for l in log:
- url = re.split("\s+", l)[6]
- ip = re.split("\s+", l)[2]
- if not args.all:
- if ip not in ips: continue
- if re.match("^\/",url): continue
- host = re.search("^(http[s]?):\/?\/?([^\/\s]+)",url)
- if host:
- site = host.group(2)
- else:
- site = url
- if site.find('.')==-1: continue
- found=False
- for s in sites:
- if s[0]==site:
- s[1]+=1
- found = True
- break
- if not found:
- sites.append([site,1])
- print "new site: %s" %site
- sites = sorted(sites, key=lambda x: int(x[1]))
- with open(outfile,'w') as f:
- for s in sites:
- f.write("%d : %s\n" %(s[1],s[0]))
- print s[1], s[0]
- def get_alarmers(iplist):
- ips = []
- interest_list = open(iplist,'r')
- for i in interest_list: ips.append(i.strip())
- return ips
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement