Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- """
- Load data from isc.sans.edu API for IP and port information.
- tdr(dot)local(at)gmail(dot)com
- """
- import urllib2
- import re
- import sys
- from xml.etree import cElementTree as et
- def howto():
- print "\nUsage: isc-info.py [-i|-p] <input>\n-i\tISC information for IP address\n-p\tISC information for port number"
- if len(sys.argv)<=2:
- howto()
- sys.exit(1)
- input = sys.argv[1]
- input2 = sys.argv[2]
- def isc_ip():
- sxml = et.fromstring(urllib2.urlopen('https://isc.sans.edu/api/ip/'+input2).read())
- for el in sxml.getiterator('ip'):
- for ch in el.getchildren():
- res = '{:>8} : {:<30}'.format(ch.tag, ch.text)
- res2 = res.replace('ip : None','')
- print res2
- def isc_port():
- sxml = et.fromstring(urllib2.urlopen('https://isc.sans.edu/api/port/'+input2).read())
- for el in sxml.getiterator('port'):
- for ch in el.getchildren():
- res = '{:>8} : {:<30}'.format(ch.tag, ch.text)
- res2 = res.replace('data : None', '***ISC Data***')
- res3 = res2.replace('services : None', '\n ***Services***')
- print res3
- for sub_ch in ch:
- res = '{:>8} : {:<30}'.format(sub_ch.tag, sub_ch.text)
- res2 = res.replace('udp : None','UDP Service')
- res3 = res2.replace('tcp : None','\n TCP Service')
- print res3
- for sub_sub_ch in sub_ch:
- print '{:>8} : {:<30}'.format(sub_sub_ch.tag, sub_sub_ch.text)
- print '\n'
- if input == '-i':
- isc_ip()
- elif input == '-p':
- isc_port()
- else:
- howto()
Add Comment
Please, Sign In to add comment