Created
March 5, 2014 22:11
-
-
Save gsquire/9377715 to your computer and use it in GitHub Desktop.
This file contains 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 getopt | |
import random | |
import sys | |
import urllib2 | |
def usage(): | |
print 'Usage of req.py:' | |
print '\tpython req.py [OPTIONS] [REQUEST(S)]' | |
print '-h: Print help and exit' | |
print '-n: How many requests to send. Default is 5' | |
def send_http_reqs(num, reqs): | |
for i in range(int(num)): | |
req = random.choice(reqs) | |
response = urllib2.urlopen(req) | |
print response.read() | |
def main(): | |
if len(sys.argv) < 2: | |
usage() | |
sys.exit(1) | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], 'hn:') | |
except getopt.GetoptError as err: | |
print str(err) | |
usage() | |
sys.exit(1) | |
num = 5 | |
for o, a in opts: | |
if o == '-h': | |
usage() | |
sys.exit(1) | |
elif o == '-n': | |
num = a | |
send_http_reqs(num, args) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment