#!/usr/bin/python # # Copyright 2012-2013 Hippo B.V. (http://www.onehippo.com) # import cookielib, urllib2, sys # the default base of all URLs of all visitors. DEFAULT_URL_BASE = 'http://localhost:8080/site' #DEFAULT_URL_BASE = 'http://localhost:8081/site' #DEFAULT_URL_BASE = 'http://www.demo.test.onehippo.com' # map of visitor IP to a list of visited paths VISITORS = {\ # SOLAR ORIENTED VISIT '199.181.132.250': [\ '/news/2010/07/Solar-powered-plane-completes-26-hour-flight.html',\ '/news/2010/05/solar-power-the-skys-the-limit.html',\ '/news/2010/07/obama-commits-billions-to-solar-firms.html',\ '/news/2010/07/solar-thermal-seeks-us-breakthrough.html',\ '/products/food/2011/11/cti-solar-oven.html',\ '/products/re-use/2010/08/solar-fan-safari-hat.html',\ '/jobs/sunpower/Product-Engineer.html',\ ], # VEGETARIAN ORIENTED '74.220.126.92': [\ '/products/food/2011/11/lentil-and-mushroom-stew.html',\ '/products/food/2011/11/artichokes.html',\ '/news/2011/03/vegetarian.html',\ '/products/food/2011/11/fennel.html',\ '/news/2011/03/vegetarian.html',\ '/products/food/2011/11/fennel.html',\ ], # PROFESSIONAL ORIENTED '212.58.241.131': [\ '/news/2014/10/solarcooking-oktober.html',\ '/news/2014/11/solarcooking-november.html',\ '/events/2011/01/india.html',\ '/events/2014/07/Water-Purification-summit.html',\ '/jobs/solar/solar-project-manager.html',\ '/jobs/IT/Green-field-tester.html',\ '/jobs/solar/solar-sales-consultant.html',\ ], # CONSUMER ORIENTED '83.149.85.230': [\ '/products/health-care/2010/07/avalon-organic-conditioner.html',\ '/products/health-care/2010/06/eco-air-purification-device.html',\ '/products/food/2011/11/artichokes.html',\ '/products/food/2011/11/lentil-and-mushroom-stew.html',\ '/products/food/2011/11/cti-solar-oven.html',\ '/products/Product+Category/Health+Care',\ ], # GADGET CONSUMER ORIENTED '119.63.198.132': [\ '/products/animal--garden/2010/08/portable-solar-lamp-with-radio.html',\ '/products/re-use/2010/08/external-laptop-charger.html',\ '/products/re-use/2010/08/eco-simple-flash-drive---usb.html',\ '/products/re-use/2010/08/portable-pocketsize-charger.html',\ '/products/re-use/2010/07/Solio-Magnesium-Solar-Charger.html',\ ], # MIXED SOLAR / VEGETARIAN ORIENTED '74.125.79.106': [\ '/news/2010/07/Solar-powered-plane-completes-26-hour-flight.html',\ '/news/2010/05/solar-power-the-skys-the-limit.html',\ '/news/2010/07/obama-commits-billions-to-solar-firms.html',\ '/news/2011/03/vegetarian.html',\ '/products/food/2011/11/fennel.html',\ ], # MIXED PROF / CONSUMER ORIENTED '74.125.79.94': [\ '/jobs/solar/solar-project-manager.html',\ '/jobs/IT/Green-field-tester.html',\ '/jobs/solar/solar-sales-consultant.html',\ '/products/food/2011/11/lentil-and-mushroom-stew.html',\ '/products/food/2011/11/cti-solar-oven.html',\ '/products/Product+Category/Health+care',\ ] } class HttpBot: def __init__(self, ip): cookie_handler= urllib2.HTTPCookieProcessor() redirect_handler= urllib2.HTTPRedirectHandler() self._opener = urllib2.build_opener(redirect_handler, cookie_handler) self._opener.addheaders = [('X-Forwarded-For', ip)] def GET(self, url): return self._opener.open(url).read() if __name__ == '__main__': url_base = DEFAULT_URL_BASE if len(sys.argv) > 1: url_base = sys.argv[1] for ip, paths in VISITORS.iteritems(): print ip bot = HttpBot(ip) for path in paths: url = url_base + path print ' ' + url try: bot.GET(url) except urllib2.URLError as e: if hasattr(e, 'reason'): print('! {0}'.format(e.reason)) elif hasattr(e, 'code'): print('! Error: {0}'.format(e.code))