in code/utility/get_fms_waf_policy.py [0:0]
def source_ip_calculate(ipName, country = "", labels = []):
#print (ipName)
#print (country)
#print (labels)
if ipName == 'user':
if country == "":
print ('picking random country')
country = random.choice(list(ipTable.keys()))
print (country)
cidrList = ipTable[country.upper()]
c = len(cidrList)
#print ("c: " + str(c))
if c == 1:
x = 0
else:
x = random.randrange(0,c)
#print ("x: " + str(x))
#print (cidrList[x])
#print (cidrList[x]['Start'])
#print (cidrList[x]['End'])
s = int.from_bytes(socket.inet_aton(cidrList[x]['Start']),'big')
e = int.from_bytes(socket.inet_aton(cidrList[x]['End']),'big')
ip = socket.inet_ntoa(struct.pack('>I', random.randint(s,e)))
response = {
"sourceip": ip,
"country": country
}
if not labels == []:
response['labels'] = labels
return (response)