Archive for July, 2011

Find All Websites on a Webserver in C#

July 31, 2011 Leave a comment

This is a handy script that can tell you how many sites are hosted on an IP address.  It uses  the Bing API, so it basically asks bing if it knows of sites on that IP address. This means that they have to be listed in bing, i.e. with public access.



 public static int SitesOnIP(string ip)
            string url = "";
            url += "Appid=92B665B5421E197DC762503859279DFEBBE0B998";
            url += "&query=IP:" + ip;
            url += "&sources=web&web.count=50";
            // "Web":{"Total":31900
            string strRegex = @"Web....Total..(?<Count>\d+)";
            WebClient web = new WebClient();
            string strJson = web.DownloadString(url);
            string strCount = Regex.Match(strJson, strRegex).Groups["Count"].Value;
            return Convert.ToInt32(strCount);
Categories: Uncategorized

A better XML to JSON proxy

July 19, 2011 Leave a comment

I was looking for a generic way to convert XML to JSON, and I came across this GAE version, however, I noted that it only converted the first node of any tree to JSON, so it missed out most of the data contained in the XML.

Lets say,  we wanted to load exchange rates into a mobile app running Javascript (read phonegap /Wrtkit /Webos), an XML feed can be found at (European central bank), but it’s easier to work with JSON than XML in Javascript. If you use the GAE (google app engine) version, then you only get USD, so I wanted to write my own proxy to fix this.

So, with the help of a free .NET Hosting account from brinkster Which worked an absolute charm – I didn’t have to put load on my own server to run this!. I installed my own XML-To-JSON Proxy:

I’ve fixed this, in a C# Implementation:



(obviously, you need to urlencode any querystring parameters after the URL in both cases)

Categories: Uncategorized

Using JSONP to show books from the Google API.

July 6, 2011 Leave a comment

JSONP is one of the few technologies that allows cross-site scripting (XSS), whether this is by design or an oversight, here is an example of a Google Book Search using JSONP

    <title>Books API Example</title>
    <div id="content"></div>
      function handleResponse(response) {
	  html = "";
      for (var i = 0; i < response.items.length; i++) {
        var item = response.items[i];
        // in production code, item.text should have the HTML entities escaped.
		html += "<hr><img src=" + item.volumeInfo.imageLinks.thumbnail + ">";
		html += "<br>" + item.volumeInfo.title;
		html += "<br>Written by ";
		for(var author in item.volumeInfo.authors)
			html+= item.volumeInfo.authors[author] + " ";
		html += "<br>Published by " + item.volumeInfo.publisher;
		html += "<br>Published on " + item.volumeInfo.publishedDate;
		if (item.volumeInfo.pageCount != undefined)
			html += "<br>Pages " + item.volumeInfo.pageCount;
		for (var identifier in item.volumeInfo.industryIdentifiers)
			var isbn = item.volumeInfo.industryIdentifiers[identifier];
			if (isbn.type=="ISBN_10")
				html += "<br><a href=" + isbn.identifier+ "/httpnetwoprog-20>";
				html += "Buy at Amazon USA</a>";
				html += "<br><a href=" + isbn.identifier+ "/wwwxamlnet-21>";
				html += "Buy at Amazon UK</a>";
	  document.getElementById("content").innerHTML = html;
    <script src=""></script>


Categories: Uncategorized