[ALUG] Using curl (or similar) bypassing DNS

Brett Parker iDunno at sommitrealweird.co.uk
Mon Jun 1 16:05:24 BST 2009


On 01 Jun 15:54, Mark Rogers wrote:
> Brett Parker wrote:
>> --- 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  ---
>>   
>
> Note to self: really must learn python! That said I think I can  
> replicate the above in PHP.
>
> Thanks for that, I should have thought about it that way round myself.  
> (I'd been thinking about how to connect by hostname but override the IP,  
> rather than connect by IP but then override the host.)

Well, the hostname is part of the HTTP/1.1 spec, it doesn't exist in HTTP/1.0
and so it's the right way round to think of it ;) Back in the HTTP/1.0 days
there wasn't a way to have multiple virtual hosts on the same IP (well, other
than different port numbers). I tend to think things through in terms of the
specs, which is quite handy :)

But, anyways - see the other post in this thread for how to do it with wget -
there's probably a way of doing that with curl but I don't know how at the
moment... oh, apparently...

curl -H "Host: the.host.name" http://the.ip.add.ress/

Should do what you're after too :)

Cheers,
-- 
Brett Parker



More information about the main mailing list