does anyone know how to programmatically quiery the list of web sites sitting at a given server IP address? And, by the way, how to prevent others from seeing what other sites your server hosts??
I don't think there's any way to do this from the outside. As long as your server configuration is secure (it should be anyway), there's no reasonable way to do it. Someone could always do an ip address lookup for every possible domain name and compare the ip addresses. There's no way you could prevent them from doing that, but it's not very realistic.
This isn't programmatic, but this site attempts to answer that question. Here's the page for stackoverflow.com's IP
EDIT: That is, it tries to answer your first question.
This is knows as a reverse DNS lookup (or simply, rDNS).
You can use the host command to do an rDNS on Linux:
$ host 22.214.171.124
You can use the nslookup command on Windows/Linux:
Most networking libraries provide some way to get this information. For example, you can use the following in Java:
But please note that you might not get a list of all the domain names that are pointing to the specified IP address. For example, the IP address in the above examples belongs to one of my servers which has several domains pointing to it but an rDNS lookup only returns a single record. Perhaps further investigation of this behaviour can help you figure out how to prevent your domain names from showing up in the rDNS lookups.
From the "outsite" or in an anonymous manner, there is no way to programatically request the list of domain names that are bound to a particular web server's IP address. Stock security built into IIS/Apache/others prevent such a thing from happening. The ability to have a web server listen for multiple domain names on a single IP address is credited to HTTP 1.1's Host Header implementation.
Websites like http://www.sitedossier.com maintain a database of domain names and their respective "www" DNS A record, then allow us to query by IP address. They likely scrape search engine results by requesting a large sampling of fake queries (say straight from a dictionary), or have implemented a basic spider themselves (which would be by far more efficient).
Perform a port scan using nmap and look for web servers.
Another site I have used with good results is http://www.sitedossier.com/ip/126.96.36.199