darkArp

Untitled

Jun 29th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import requests, json, sys
  2. from time import sleep
  3. from collections import Counter
  4. ip_addr = []
  5. countries = []
  6. api_key = "b8c3cc5bb9e845"
  7. def getIP():
  8.     import socket, csv
  9.     with open('JAR-16-20296A.csv') as csv_file:
  10.         reader = csv.DictReader(csv_file)
  11.         for row in reader:
  12.             line = [row['INDICATOR_VALUE']]
  13.             line = [item.replace("[.]", ".") for item in line]
  14.             try:
  15.                 socket.inet_aton(line[0])
  16.                 ip_addr.append(line[0])
  17.             except socket.error:
  18.                 continue
  19.     return 0
  20. def printList(list):
  21.     for item in list:
  22.         print(item)
  23. def update_progress(job_title, progress):
  24.     length = 20
  25.     block = int(round(length*progress))
  26.     msg = "\r{0}: [{1}] {2}%".format(job_title, "#"*block + "-"*(length-block), round(progress*100, 2))
  27.     if progress >= 1: msg += " DONE\r\n"
  28.     sys.stdout.write(msg)
  29.     sys.stdout.flush()
  30. def getCountries():
  31.     i = 0
  32.     x = 100/len(ip_addr)
  33.     for ip in ip_addr:
  34.         url = "https://www.ipinfo.io/" + ip + "/geo/" + "?token=" + api_key
  35.         r = requests.get(url, verify=True)
  36.         if r.status_code == 200:
  37.             data = json.loads(r.content)
  38.             countries.append(data['country'])
  39.             update_progress("Progress", i/100.0)
  40.             i = i + x
  41.         elif r.status_code == 429:
  42.             print("Request limit reached")
  43.             return
  44.         else:
  45.             print("Other HTTP error...")
  46. def getTop(in_list, number):
  47.     c = Counter(in_list)
  48.     return c.most_common(number)
  49.  
  50. def howMany(in_list, name):
  51.     c = Counter(in_list)
  52.     return c[name]
  53. getIP() # This creates the IP list, has to always be run first.
  54. getCountries() # This creates another list that has all the countries from where the IPs came from.
  55.                 # It has a progress bar because it is going to take long, I didn't make it very efficient because
  56.                 # I don't know what kind of modules you're allowed to use.
  57.  
  58. #print(getTop(countries,3))  # This gets the 3 countries more common on the list!
  59. #print(howMany(countries, "RU")) #This gets how many entries Russia has on the list
  60.  
  61. #printList(ip_addr) # This prints the list of IP adresses.
Advertisement
Add Comment
Please, Sign In to add comment