I'm trying to make a small script to send GET requests to a Host that has multiple IP addresses.
So far I was able to make the script send the GET requests with those different IPs all at once(same time), is there a simple way to make it so I provide the list of IPs and it would send the requests with IP#1 then next request with IP#2, etc..
Ps: here is the full code so you can understand a bit what I'm asking, and if you feel like improving it you can let me know too :)
Thanks for your help ! :D
#!/usr/bin/env python
import requests
import ujson
import time
import random
url = 'site'
headeR = {'Host': 'site.com'}
while 1:
hosts = ['X.X.X.235', 'X.X.X.94', 'X.X.X.191', 'X.X.X.247']
cnt = 0
while cnt<len(hosts):
currentUrl = url.replace("site.com", hosts[cnt])
cnt += 1
r = requests.get(currentUrl , headers=headeR)
listingInfoStr = r.content
result= ujson.loads(listingInfoStr)
listingInfoJson= result['listinginfo']
if listingInfoJson:
for key, value in listingInfoJson.iteritems():
#print("key %s, value %s" % (key, value))
listingId = key
try:
subTotal = value["converted_price_per_unit"]
feeAmount = value["converted_fee_per_unit"]
except KeyError:
continue
totalPrice = subTotal + feeAmount
totalPriceFloat = float(totalPrice) / 100
print("listingId %s = [ %s + %s = %s ]" % (listingId, subTotal, feeAmount, totalPrice))
else:
print "Still Looking"
time.sleep(25)