Guest User

Untitled

a guest
Feb 17th, 2012
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. from subprocess import call
  3. import ipaddr
  4.  
  5. def description(i):
  6. descr = open('descr', 'r')
  7. ind=0
  8. des = ""
  9. for line in descr:
  10. line = line.split(':')
  11. if line[0] == 'descr' and ind==i:
  12. des = des + ',' + line[1].strip()
  13. elif line[0] == 'country' and ind<=i:
  14. ind = ind + 1
  15. return des
  16.  
  17.  
  18. prefixes = ["46.251.64.0/19","88.81.32.0/19","89.189.0.0/19","92.242.64.0/19","149.62.0.0/19","195.98.32.0/19","212.92.128.0/18"]
  19.  
  20. #call( "rm inetnum netname descr", shell=True)
  21.  
  22. #for prefix in prefixes:
  23. # call( "whois -h whois.ripe.net -- -M "+ prefix +" | egrep -o '(inetnum.*)' >> inetnum", shell=True)
  24. # call( "whois -h whois.ripe.net -- -M "+ prefix +" | egrep -o '(netname.*)' >> netname", shell=True)
  25. # call( "whois -h whois.ripe.net -- -M "+ prefix +" | egrep -o '(descr.*)|(country.*)' >> descr", shell=True)
  26.  
  27. inetnums = open('inetnum', 'r')
  28. netnames = open('netname', 'r')
  29. nets=[]
  30. inets=[]
  31.  
  32.  
  33. for i in inetnums:
  34. inets.append(i)
  35.  
  36. for n in netnames:
  37. nets.append(n)
  38.  
  39.  
  40. for inetnum in inets:
  41. index = inets.index(inetnum)
  42. inetnum = inetnum.split(':')
  43. inetnum = inetnum[1].strip()
  44. netname = nets[index]
  45. netname = netname.split(':')
  46. netname = netname[1].strip()
  47. netname = netname.strip()
  48. desc = description(index)
  49. ip = inetnum.split(" - ")
  50. sub = ipaddr.summarize_address_range (ipaddr.IPv4Address(ip[0]), ipaddr.IPv4Address(ip[1]))
  51. for a in sub:
  52. print str(a) + ',8371,Global,4,"' + netname + ", " + desc + '"'
RAW Paste Data