PHPackages                             shiniv/dns - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. shiniv/dns

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shiniv/dns
==========

A PHP library for creating DNS zone files based on RFC1035

v0.25(4y ago)0171[1 PRs](https://github.com/shiniv/DNS/pulls)MITPHPPHP ^7.3 || ^8.0

Since Aug 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/shiniv/DNS)[ Packagist](https://packagist.org/packages/shiniv/dns)[ RSS](/packages/shiniv-dns/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (5)Versions (27)Used By (0)

Badcow DNS Library
==================

[](#badcow-dns-library)

The aim of this project is to create abstract object representations of DNS records in PHP. The project consists of various classes representing DNS objects (such as `Zone`, `ResourceRecord`, and various `RData` types), a parser to convert BIND style text files to the PHP objects, and builders to create aesthetically pleasing BIND records.

The library can parse and encode DNS messages enabling developers to create DNS client/server platforms in pure PHP.

Build Status
------------

[](#build-status)

[![Build Status: PHP 7](https://github.com/Badcow/DNS/workflows/PHP%207/badge.svg)](https://github.com/Badcow/DNS/actions?query=workflow%3A%22PHP+7%22)[![Build Status: PHP 8](https://github.com/Badcow/DNS/workflows/PHP%208/badge.svg)](https://github.com/Badcow/DNS/actions?query=workflow%3A%22PHP+8%22)

Contents
--------

[](#contents)

1. [Example usage](#example-usage)
2. [Example Output](#output)
3. [Supported Types](#supported-types)
4. [Parsing BIND Records](#parsing-bind-records)

Example usage
-------------

[](#example-usage)

```
require_once '/path/to/vendor/autoload.php';

use Badcow\DNS\Classes;
use Badcow\DNS\Zone;
use Badcow\DNS\Rdata\Factory;
use Badcow\DNS\ResourceRecord;
use Badcow\DNS\AlignedBuilder;

$zone = new Zone('example.com.');
$zone->setDefaultTtl(3600);

$soa = new ResourceRecord;
$soa->setName('@');
$soa->setClass(Classes::INTERNET);
$soa->setRdata(Factory::Soa(
    'example.com.',
    'post.example.com.',
    '2014110501',
    3600,
    14400,
    604800,
    3600
));

$ns1 = new ResourceRecord;
$ns1->setName('@');
$ns1->setClass(Classes::INTERNET);
$ns1->setRdata(Factory::Ns('ns1.nameserver.com.'));

$ns2 = new ResourceRecord;
$ns2->setName('@');
$ns2->setClass(Classes::INTERNET);
$ns2->setRdata(Factory::Ns('ns2.nameserver.com.'));

$a = new ResourceRecord;
$a->setName('sub.domain');
$a->setRdata(Factory::A('192.168.1.42'));
$a->setComment('This is a local ip.');

$a6 = new ResourceRecord;
$a6->setName('ipv6.domain');
$a6->setRdata(Factory::Aaaa('::1'));
$a6->setComment('This is an IPv6 domain.');

$mx1 = new ResourceRecord;
$mx1->setName('@');
$mx1->setRdata(Factory::Mx(10, 'mail-gw1.example.net.'));

$mx2 = new ResourceRecord;
$mx2->setName('@');
$mx2->setRdata(Factory::Mx(20, 'mail-gw2.example.net.'));

$mx3 = new ResourceRecord;
$mx3->setName('@');
$mx3->setRdata(Factory::Mx(30, 'mail-gw3.example.net.'));

$zone->addResourceRecord($soa);
$zone->addResourceRecord($mx2);
$zone->addResourceRecord($ns1);
$zone->addResourceRecord($mx3);
$zone->addResourceRecord($a);
$zone->addResourceRecord($a6);
$zone->addResourceRecord($ns2);
$zone->addResourceRecord($mx1);

$builder = new AlignedBuilder();
echo $builder->build($zone);
```

### Output

[](#output)

```
$ORIGIN example.com.
$TTL 3600
@            IN SOA  (
                     example.com.      ; MNAME
                     post.example.com. ; RNAME
                     2014110501        ; SERIAL
                     3600              ; REFRESH
                     14400             ; RETRY
                     604800            ; EXPIRE
                     3600              ; MINIMUM
                     )

; NS RECORDS
@            IN NS   ns1.nameserver.com.
@            IN NS   ns2.nameserver.com.

; A RECORDS
sub.domain      A    192.168.1.42; This is a local ip.

; AAAA RECORDS
ipv6.domain     AAAA ::1; This is an IPv6 domain.

; MX RECORDS
@               MX   10 mail-gw1.example.net.
@               MX   20 mail-gw2.example.net.
@               MX   30 mail-gw3.example.net.
```

The above is an example of the `AlignedBuilder` which creates records that are much more aesthetically pleasing. You can also use the flat `ZoneBuilder`, the output of which is below:

```
...
echo ZoneBuilder::build($zone);
```

```
$ORIGIN example.com.
$TTL 3600
@ IN SOA example.com. post.example.com. 2014110501 3600 14400 604800 3600
@ MX 20 mail-gw2.example.net.
@ IN NS ns1.nameserver.com.
@ MX 30 mail-gw3.example.net.
sub.domain A 192.168.1.42; This is a local ip.
ipv6.domain AAAA ::1; This is an IPv6 domain.
@ IN NS ns2.nameserver.com.
@ MX 10 mail-gw1.example.net.
```

Supported Types
---------------

[](#supported-types)

All ubiquitous DNS types are supported. For full details on supported types see [the Documentation](docs/Supported-Types.md).

Parsing BIND Records
--------------------

[](#parsing-bind-records)

BIND Records can be parsed into PHP objects using `Badcow\DNS\Parser\Parser`

```
$file = file_get_contents('/path/to/example.com.txt');
$zone = Badcow\DNS\Parser\Parser::parse('example.com.', $file); //Badcow Zone Object
```

Simple as that.

More examples can be found in the [The Docs](docs/Parser)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 93.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~99 days

Recently: every ~334 days

Total

26

Last Release

1799d ago

Major Versions

v0.19 → v1.0.x-dev2017-04-19

PHP version history (4 changes)v0.1PHP &gt;=5.4

v0.16PHP &gt;=5.5

v1.0.x-devPHP &gt;=5.6

v0.22PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/003dcd0244f0d143acea6138186422c2429609fd95d6bf85557e4f6c8c1037b2?d=identicon)[shiniv](/maintainers/shiniv)

---

Top Contributors

[![samuelwilliams](https://avatars.githubusercontent.com/u/806430?v=4)](https://github.com/samuelwilliams "samuelwilliams (426 commits)")[![shiniv](https://avatars.githubusercontent.com/u/3983330?v=4)](https://github.com/shiniv "shiniv (12 commits)")[![Livda](https://avatars.githubusercontent.com/u/9930567?v=4)](https://github.com/Livda "Livda (9 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (3 commits)")[![srsbiz](https://avatars.githubusercontent.com/u/1525842?v=4)](https://github.com/srsbiz "srsbiz (2 commits)")[![fbett](https://avatars.githubusercontent.com/u/24937658?v=4)](https://github.com/fbett "fbett (1 commits)")[![adamnicholson](https://avatars.githubusercontent.com/u/7761178?v=4)](https://github.com/adamnicholson "adamnicholson (1 commits)")[![a3dho3yn](https://avatars.githubusercontent.com/u/5849028?v=4)](https://github.com/a3dho3yn "a3dho3yn (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/shiniv-dns/health.svg)

```
[![Health](https://phpackages.com/badges/shiniv-dns/health.svg)](https://phpackages.com/packages/shiniv-dns)
```

###  Alternatives

[jxlwqq/chinese-typesetting

Better Typesetting for Chinese

852.1k](/packages/jxlwqq-chinese-typesetting)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
