daily pastebin goal
77%
SHARE
TWEET

test script

a guest Jun 23rd, 2018 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2.                      
  3. def test():
  4.     for f in ["ads.csv","fraud.csv"]:
  5.         output = open("result_%s" % f,"w")
  6.         allowed_cnt = 0
  7.         blocked_cnt = 0
  8.         unresolved_cnt = 0
  9.         urls = sorted([x for x in open(f,"r").read().split("\n") if x !=""])
  10.         for url in urls:
  11.             try:
  12.                 ips = socket.getaddrinfo(url,0,0,0,0)
  13.                 if len([True for ip in ips if ip[-1][-2].startswith("127.0.0.") or ip[-1][-2] == "1.2.3.1" ]) > 0:
  14.                     print("Blocked: %s" % url)
  15.                     output.write("Blocked\t%s\n" % url)
  16.                     blocked_cnt += 1
  17.                 else:
  18.                     print("Allowed: %s" % url)
  19.                     output.write("Allowed\t%s\n" % url)
  20.                     allowed_cnt += 1
  21.             except:
  22.                 print("Unresolved: %s" % url)
  23.                 output.write("Unresolved\t%s\n" % url)
  24.                 unresolved_cnt += 1
  25.         r = "%s resolved, %s blocked, %s unresolved" % (allowed_cnt, blocked_cnt, unresolved_cnt)
  26.         output.write("%s\n" % r)
  27.         output.close()
  28.         print(r)
  29.        
  30. test()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top