[ALUG] Using curl (or similar) bypassing DNS

David Reynolds david at reynoldsfamily.org.uk
Mon Jun 1 14:28:26 BST 2009

On 1 Jun 2009, at 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.

If I understand what you're saying correctly (and it took me a couple  
of reads to get to the point I'm at now, so it's quite possible I  
don't..),  I think you might want to script something like

telnet server.ip.address 80
GET / HTTP/1.1
Host: www.the-virtualhost-you-want-to-test.com

That way you are talking to the server you think the site is on,  
regardless of the DNS.

You ought to be able to script the above with some sort of socket  
library, as you suggested



David Reynolds
david at reynoldsfamily.org.uk

More information about the main mailing list