Thursday, 20 February 2014

IP location information

I made to have IP location information from IPs.

 import urllib  
   
 def iplocation(*data):  
   response = urllib.urlopen('http://api.hostip.info/get_html.php?ip='+ data[0]+'&position=true').read()  
   return response  
   
 iplists = open('iplists.txt','r')  
 save = open('result.csv', 'w')  
 for ip in iplists:  
   ip = str(ip).replace("\n","")  
   print " "*8 + "[-] " + ip  
   response = iplocation(ip)  
   response = response.split("\n")  
   county = response[0].split(":")  
   result = county[1].strip()  
   save.write(ip + ",\"" + result + "\"\n")  
   if result:  
     print " "*12 + result  
 iplists.close()  
 save.close()  
   

Put IPs into iplists.txt, then it makes result.csv.

DNS BLACK LIST Information

I need to analysis some IPs, so I need to check DNS BLACK LISTS.

I made simple checking DNS black Lists using python.

 import os  
 import re  
 import socket  
 import sys  
 import requests  
 from BeautifulSoup import BeautifulSoup  
 USER_AGENT = "Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1"  
 PRAGMA = "no-cache"  
 ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"  
 def blacklist(dat):  
   ip = dat  
   type =None  
   status = ""  
   #path = "/query/bl?ip="  
   #path +=ip  
   host = "http://www.spamhaus.org/query/bl?ip="+ip  
   USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"  
   PRAGMA = "no-cache"  
   ACCEPT = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"  
   results = requests.get(host,  
               params = {"ip": ip},  
               headers = {"Host": "www.spamhaus.org",  
                    "User-Agent": USER_AGENT,  
                    "Accept": ACCEPT,  
                    "Accept-Encoding": "gzip, deflate",  
                    "Accept-Language": "ko-KR",  
                    "Connection": "keep-alive"  
                    }  
               )  
   try:   
     html = results.text  
   except UnicodeDecodeError:  
     html = u' '.join(results.text).encode('utf-8').strip()  
   soup = BeautifulSoup(html)  
   tag = soup.findAll('b')  
   for item in tag:  
     if "is listed in the" in item.text:  
       #print item.text  
       status = "Block"  
       return status  
     else :  
       status = "Allow"  
   return status  
 iplists = open('iplists.txt','r')  
 save = open('result.csv', 'w')  
 for ip in iplists:  
   ip = str(ip).replace("\n","")  
   print " "*8 + "[-] " + ip  
   try:   
     result = blacklist(ip)  
   except UnicodeDecodeError:  
     result = u' '.join(blacklist(ip)).encode('utf-8').strip()  
   save.write(ip + ",\"" + result + "\"\n")  
   if result:  
     print " "*12 + result  
 iplists.close()  
 save.close()  

Input IPs to iplists.txt, then it makes result.csv.

How to have window update IP ranges.

I have considering a problem how to get window update IP ranges.
I could find window update URLs. However, our firewall could not using URL information.
It could use only IP that makes the problem.

Just I share window update URL.
 www.update.microsoft.com  
 update.microsoft.com  
 v5.windowsupdate.microsoft.com  
 download.windowsupdate.com  
 c.microsoft.com  
 windowsupdate.microsoft.com  
 v4.windowsupdate.microsoft.com  
 windowsupdate.com  
 ntservicepack.microsoft.com  
 wustat.windows.com  
 au.download.windowsupdate.com  
 updates.installshield.com  
 microsoft.com  
 urs.microsoft.com  
 go.microsoft.com  
 start.microsoft.com  
 crl.microsoft.com  
 catalog.update.microsoft.com  
 validation.sls.microsoft.com  
 na.activation.sls.microsoft.com  
 activation.sls.microsoft.com  
 sls.microsoft.com.nsatc.net  
 validation.sls.microsoft.com.nsatc.net  
 activation.sls.microsoft.com.nsatc.net  
 emea.activation.sls.microsoft.com  
 mpa.one.microsoft.com  
 download.microsoft.com  

The Window update IPs are flexibled...