Download the PHP package sirmonti/doh without Composer
On this page you can find all versions of the php package sirmonti/doh. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package doh
Short Description DNS over HTTPS client library
License MIT
Homepage https://github.com/sirmonti/DOH
Informations about the package doh
DOH - DNS over HTTPS client library for PHP
Introduction
DNS resolve is a well known function that is implemented in all operating systems, then, Why we need a different way to do it? The main reason is privacy, standard DNS protocol don't encrypt connections, which means DNS requests can be spied and forged.
But there are other reasons; first, DOH is fast, more fast than a lot of local servers. This is not very surprisingly if you consider that cloudflare and google (the main DOH providers) have huge network infraestructures. But there are more, DOH provides a more descriptive errors. For example, standard DNS servers can misinterpret network errors as nonexistent records. DOH will correctly report the error.
If you need a fast and reliable DNS name resolution, If you need fast and reliable name resolution, more precisely, if you need bulk name resolution, DOH provides a better solution than standard DNS servers.
Complete documentation can be found in the github.io page
Install
Vía composer
Usage
Actually, the library supports two DoH providers, cloudflare and google. The support is implemented across two wrapper classes:
- DOHGG: Resolves names via google
- DOHCF: Resolves names via cloudflare
There isn't any differente to use one class or another. The only reason to prefer one or the other is the sympathy you have for the company.
The classes are called statically, there is no need to create an object. For example, if you want to get the IP address for www.google.com using google backend, the call will be:
If you have more sympathy for cloudflare, you can use it as a backend
The classes have the following methods:
function | Description |
---|---|
IPtoDNS($ip) | Convert an IP address to a DNS encoding valid for PTR querys |
dns($name,$type) | Resolve a DNS query. $name is the name to resolve and $type is the record type searched |
getStatus() | Get the status code for the last query |
DNS resolution
The method "dns($name,$type)" execute a DNS query. The query return an array with the responses. In case of error the function returns an empty array and set "status" attribute with the error code. The parameters are the name we want resolve and the record type we are asking for.
When parameters have an invalid value, an InvalidValurException will be fired, network or DNS error doesn't fire any exception, error will be reported with an status code.
Valid record types: NS, MX, TXT, A, AAAA, CNAME, SPF, SOA, PTR, SRV, DS, DNSKEY
The response is an array with the returned responses. If the query don't have a valid response or an error ocurrs, the call will return an empty array and set the "status" property to the error code. If all is ok, the status code will be zero.
status code values:
- 0: OK
- 1: Empty response. There are not response to this query.
- 2: The DNS servers for this domain are misconfigured
- 3: The domain does not exist
- 4: Network error
- 5: Lame response
- 100: Invalid record type provided
- 101: Invalid IP address provided
- 10XX: Values above 1000 contains error code returned by DNS server
On invalid parameters an InvalidArgumentException will be fired with the status codes 100 or 101.
Examples
The script produces this response
In this example, we use the DOH_PROVIDER constant to set the resolver
The script produces this response
Example for a bogus query. We use the hardcoded default resolver
The script produces this response
LICENSE
This library is licensed under MIT LICENSE