{"id":13584697,"url":"https://github.com/spatie/dns","last_synced_at":"2025-05-14T01:10:52.162Z","repository":{"id":41148644,"uuid":"108810419","full_name":"spatie/dns","owner":"spatie","description":"Retrieve DNS records","archived":false,"fork":false,"pushed_at":"2025-04-10T12:37:21.000Z","size":225,"stargazers_count":587,"open_issues_count":0,"forks_count":96,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-14T04:01:51.528Z","etag":null,"topics":["dns","hacktoberfest","php"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-10-30T06:25:35.000Z","updated_at":"2025-04-10T12:37:26.000Z","dependencies_parsed_at":"2025-04-14T02:59:28.610Z","dependency_job_id":"e3d018ee-240a-4444-94be-e67494f70e9c","html_url":"https://github.com/spatie/dns","commit_stats":{"total_commits":227,"total_committers":40,"mean_commits":5.675,"dds":0.4845814977973568,"last_synced_commit":"3765d5f625c4e55cb864c8938de8e322ecd71b32"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fdns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fdns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fdns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fdns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/dns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254049283,"owners_count":22006032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","hacktoberfest","php"],"created_at":"2024-08-01T15:04:27.253Z","updated_at":"2025-05-14T01:10:47.153Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Retrieve DNS records\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/dns.svg?style=flat-square)](https://packagist.org/packages/spatie/dns)\n[![Tests](https://github.com/spatie/dns/actions/workflows/tests.yml/badge.svg)](https://github.com/spatie/dns/actions/workflows/tests.yml)\n[![Code style](https://github.com/spatie/dns/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/spatie/dns/actions/workflows/php-cs-fixer.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/dns.svg?style=flat-square)](https://packagist.org/packages/spatie/dns)\n\nThis package contains a class that can fetch DNS records.\n\n```php\nuse Spatie\\Dns\\Dns;\n\n$dns = new Dns();\n\n$dns-\u003egetRecords('spatie.be'); // returns all available dns records\n\n$dns-\u003egetRecords('spatie.be', 'A'); // returns only A records\n```\n\nYou can use various methods to retrieve info of a record.\n\n```php\n$records = $dns-\u003egetRecords('spatie.be')\n\n$hostNameOfFirstRecord = $records[0]-\u003ehost();\n```\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/dns.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/dns)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nIf you do not have [dig](https://linux.die.net/man/1/dig) installed you will need it.\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/dns\n```\n\n## Usage\n\nThe class can get these record types: `A`, `AAAA`, `CNAME`, `NS`, `PTR`, `SOA`, `MX`, `SRV`, `TXT`, `DNSKEY`, `CAA`, `NAPTR`.\n\n```php\nuse Spatie\\Dns\\Dns;\n\n$dns = new Dns();\n\n$dns-\u003egetRecords('spatie.be'); // returns all available dns records\n\n$dns-\u003egetRecords('spatie.be', 'A'); // returns only A records\n$dns-\u003egetRecords('spatie.be', ['A', 'CNAME']); // returns both A and CNAME records\n$dns-\u003egetRecords('spatie.be', DNS_MX); // returns only MX records\n$dns-\u003egetRecords('spatie.be', DNS_A | DNS_AAAA); // returns both A and AAAA records\n```\n\n`getRecords` will return an array with objects that implement the `Spatie\\Dns\\Records\\Record` interface.\n\n## Working with DNS records\n\nHere's how you can fetch the first A-record of a domain.\n\n```php\n$ARecord = $dns-\u003egetRecords('spatie.be', 'A')[0];\n```\n\nThese methods can be called on all records:\n\n- `host()`: returns the host (`spatie.be`)\n- `ttl()`: return the time to live (`900`)\n- `class()`: returns the class (`IN`)\n- `type()`: returns the type (`A`)\n\nWhen converting a record to a string you'll get a string with all info separated with tabs.\n\n```php\n(string)$ARecord // returns `spatie.be.              900     IN      A       138.197.187.74`\n```\n\nSome records have additional methods available. For example, records of type A [have an additional `ip()` method](https://github.com/spatie/dns/blob/72bf709a44e19e5d8f0bc7e6c93cf70e7a1b18f3/src/Records/A.php#L6). To know which extra methods there are, check the docblocks above [all record classes](https://github.com/spatie/dns/tree/72bf709a44e19e5d8f0bc7e6c93cf70e7a1b18f3/src/Records) in the source code.\n\n## Using a specific nameserver\n\nYou can get records from a specific nameserver.\n\n```php\nuse Spatie\\Dns\\Dns;\n\n(new Dns)\n    -\u003euseNameserver('ns1.openminds.be') // use ns1.openminds.be\n    -\u003egetRecords('spatie.be');\n```\n\n## Specify retries and timeouts for Dig\n\nDig can be configured to retry a DNS query after a certain timeout. Use `setRetries()` or `setTimeout()` to configure\nthose settings. The timeout is specified in seconds.\n\n```php\nuse Spatie\\Dns\\Dns;\n\n(new Dns)\n    -\u003esetRetries(4) // try 4 times\n    -\u003esetTimeout(5) // wait 5 seconds for a reply from the nameserver\n    -\u003egetRecords('spatie.be');\n```\n\n## Guessing a record\n\nWhen you have a string that contains a dns record, you can convert it to a `Record`\n\n```php\nuse \\Spatie\\Dns\\Support\\Factory();\n\n// returns instance of \\Spatie\\Dns\\Records\\CNAME\n(new Factory())-\u003eguess('www.spatie.be.       300     IN      CNAME   spatie.be.');\n```\n\n## Using custom handlers\n\nA `Handler` is responsible for fetching DNS records of a certain type.\n\nBy default, these handlers that ship with the package are used:\n\n- `Spatie\\Dns\\Handler\\Dig`\n- `Spatie\\Dns\\Handler\\DnsGetRecord`\n\nYou can create custom handlers. A valid handler is any class that extends from `Spatie\\Dns\\Handler\\Handler`.\n\nA custom handler class can be used by passing it to `useHandlers` on `Spatie\\Dns\\Dns`.\n\n```php\n$results = $this-\u003edns\n    -\u003euseHandlers([new YourCustomHandler()])\n    -\u003egetRecords('spatie.be');\n```\n\n## Under the hood\n\nWe will use [dig](https://wiki.ubuntuusers.de/dig/) to fetch DNS info. If it is not installed on your system, we'll call the native `dns_get_record()` function.\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n### Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be).\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Harish Toshniwal](https://github.com/introwit)\n- [Tom Witkowski](https://github.com/Gummibeer)\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fdns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fdns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fdns/lists"}