Inkeliz
Inkeliz

Reputation: 1091

Block DNS Lookup on Curl (PHP)

How I can block the DNS Lookup on Curl?

So, I think have two alternatives, there is:

  1. Use HTTP (or another type?) Proxies. But, the DNS Loockup will be made by Proxy or the 'original' server?

Exemple: curl_setopt($ch, CURLOPT_PROXY, '0.0.0.');

  1. Set a default DNS for domain. In Windows se have a "ETC/HOSTS" file, but where it is on Centos? How I can set this default in CURL? Because the CURL will continue try find the DNS.

This will work?

Thank everyone. :)

Upvotes: 1

Views: 2710

Answers (1)

Sammitch
Sammitch

Reputation: 32232

If you're trying to force a request to a different server than what DNS specifies then you can muck with /etc/hosts or C:\Windows\System32\drivers\etc\hosts, OR you can do it purely through cURL by manually setting a host header.

$hostname = 'www.mydomain.com';
$ip = '1.2.3.4';
$proto = 'http';
$request = '/foo/bar/index.php';

$url = sprintf('%s://%s%s', $proto, $ip, $request); // http://1.2.3.4/foo/bar/index.php

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Host: '.$hostname]);
curl_exec($ch);

Upvotes: 3

Related Questions