salawank

isc-info.py

Jan 7th, 2014
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env python
  2. """
  3. Load data from isc.sans.edu API for IP and port information.
  4. tdr(dot)local(at)gmail(dot)com
  5. """
  6. import urllib2
  7. import re
  8. import sys
  9. from xml.etree import cElementTree as et
  10.  
  11. def howto():
  12.     print "\nUsage: isc-info.py [-i|-p] <input>\n-i\tISC information for IP address\n-p\tISC information for port number"
  13.  
  14. if len(sys.argv)<=2:
  15.     howto()
  16.     sys.exit(1)
  17.    
  18. input = sys.argv[1]
  19. input2 = sys.argv[2]
  20.  
  21. def isc_ip():
  22.     sxml = et.fromstring(urllib2.urlopen('https://isc.sans.edu/api/ip/'+input2).read())
  23.     for el in sxml.getiterator('ip'):
  24.         for ch in el.getchildren():
  25.             res = '{:>8} : {:<30}'.format(ch.tag, ch.text)
  26.             res2 = res.replace('ip : None','')
  27.             print res2
  28.            
  29. def isc_port():
  30.     sxml = et.fromstring(urllib2.urlopen('https://isc.sans.edu/api/port/'+input2).read())
  31.     for el in sxml.getiterator('port'):
  32.         for ch in el.getchildren():
  33.             res = '{:>8} : {:<30}'.format(ch.tag, ch.text)
  34.             res2 = res.replace('data : None', '***ISC Data***')
  35.             res3 = res2.replace('services : None', '\n  ***Services***')
  36.             print res3
  37.             for sub_ch in ch:
  38.                 res = '{:>8} : {:<30}'.format(sub_ch.tag, sub_ch.text)
  39.                 res2 = res.replace('udp : None','UDP Service')
  40.                 res3 = res2.replace('tcp : None','\n     TCP Service')
  41.                 print res3
  42.                 for sub_sub_ch in sub_ch:
  43.                     print '{:>8} : {:<30}'.format(sub_sub_ch.tag, sub_sub_ch.text)
  44.                
  45. print '\n' 
  46. if input == '-i':
  47.     isc_ip()
  48. elif input == '-p':
  49.     isc_port()
  50. else:
  51.     howto()
RAW Paste Data