On 01 Jun 14:14, Mark Rogers wrote:
Does anyone know how I can bypass DNS requests in a general way so that I can do, say: curl http://www.microsoft.com .. but bypassing the DNS lookup so that I can specify the IP I want the http request targetted at?
In a simple case I can just add www.microsoft.com to my hosts file, but if I wanted to write (say) a bash or PHP script which did this then it would get messy using hosts that way.
What I am looking to do is automate some checks which will run on an Apache server and ensure that all the virtual hosts on the server are working correctly. It is not possible to assume that all site shave the DNS pointed at the server (for example it may be a site which is being migrated to the server at some point in the near future).
I may just write my own code to make http(s) requests directly using a socket library or something a bit higher level than that but below curl, but I'd prefer to use a standard tool if possible.
Alternatively, this is really simple in python...
--- Begin Snippet ---
import urllib2
req = urllib2.Request("http://ip.add.of.server/path/to/thing/") req.add_header("Host", "the hostname you really want to present") resp = urllib2.urlopen(req) data = resp.read()
--- End Snippet ---
Now the content will be in data (unless it hit a 404, in which case it'll have thrown an Exception and you'll be outside of the scope of the snippet ;)
Cheers,