All Projects → Badcow → DNS-Parser

Badcow / DNS-Parser

Licence: MIT license
This library parses BIND zone files and outputs DNS objects.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to DNS-Parser

zonemanager
Central DNS/DHCP database with replication to Amazon Route53, BIND, MikroTik routers and other services.
Stars: ✭ 29 (+81.25%)
Mutual labels:  bind, bind9
dnstap-receiver
Dnstap streams receiver in Python
Stars: ✭ 33 (+106.25%)
Mutual labels:  bind
NetworkAdapterSelector
A simple solution to let you force bind a program to a specific network adapter
Stars: ✭ 168 (+950%)
Mutual labels:  bind
ObservableComputations
Cross-platform .NET library for computations whose arguments and results are objects that implement INotifyPropertyChanged and INotifyCollectionChanged (ObservableCollection) interfaces.
Stars: ✭ 94 (+487.5%)
Mutual labels:  bind
mercator
Automatic typeclass-based abstraction over monad-like types
Stars: ✭ 54 (+237.5%)
Mutual labels:  bind
laravel-route-model-autobinding
THIS PACKAGE HAS BEEN DEPRECATED — Automatically bind Eloquent models as route segment variables.
Stars: ✭ 14 (-12.5%)
Mutual labels:  bind
ansible-role-dns
Install and configure dns on your system.
Stars: ✭ 39 (+143.75%)
Mutual labels:  bind
RCE-python-oneliner-payload
Python bind shell single line code for both Unix and Windows, used to find and exploit RCE (ImageMagick, Ghostscript, ...)
Stars: ✭ 23 (+43.75%)
Mutual labels:  bind
bind.ts
Function.prototype.bind with typings for TypeScript
Stars: ✭ 15 (-6.25%)
Mutual labels:  bind
skinner
Skin export / import tools for Autodesk Maya
Stars: ✭ 68 (+325%)
Mutual labels:  bind
bind-to-tinydns
Convert zone files from the BIND DNS server into configs for djbdns's tinydns
Stars: ✭ 18 (+12.5%)
Mutual labels:  bind
LaraSible
A complete ansible playbook for create a hosting envorinment with Nginx, PHP-FPM, Redis and MariaDB for Laravel Framework on Linux
Stars: ✭ 15 (-6.25%)
Mutual labels:  bind9
hosts
冷莫(trli)的规则唯一一个提供全球比较全的库Cold Mo (TRLI) rules is the only one to provide a global comparison of the library.
Stars: ✭ 4 (-75%)
Mutual labels:  bind9

!! Code-base has been moved !!

The DNS Parser has been incorporated into Badcow DNS Zone Library to enable a better release cycle. The namespaces remain unchanged. You only need to include badcow/dns in your composer config.

Badcow DNS Zone Parser

This library parses DNS zone files and outputs DNS objects (see Badcow DNS Zone Library)

Build Status

Build Status Code Coverage Scrutinizer Code Quality

Usage

$file = file_get_contents('/path/to/example.com.txt');

$zone = Badcow\DNS\Parser\Parser::parse('example.com.', $file);

Simple as that.

Installation

Using composer...

"require": {
        "badcow/dns-parser": "~1.0"
    }

Example

BIND Record

$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
@               NS   ns1.nameserver.com.
@               NS   ns2.nameserver.com.

info            TXT "This is some additional \"information\""

 ; 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.

mail     IN     TXT  "THIS IS SOME TEXT; WITH A SEMICOLON"

Processing the record

<?php

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

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

$zone->getName(); //Returns example.com.
foreach ($zone->getResourceRecords() as $record) {
    $record->getName();
    $record->getClass();
    $record->getTtl();
    $record->getRdata()->output();
}

Using Custom RData Handlers

Out-of-the-box, the library will handle most RData types that are regularly encountered. Occasionally, you may encounter an unsupported type. You can add your own RData handler method for the record type. For example, you may want to support the non-standard SPF record type, and return a TXT instance.

$spf = function (\ArrayIterator $iterator): Badcow\DNS\Rdata\TXT {
    $string = '';
    while ($iterator->valid()) {
        $string .= $iterator->current() . ' ';
        $iterator->next();
    }
    $string = trim($string, ' "'); //Remove whitespace and quotes

    $spf = new Badcow\DNS\Rdata\TXT;
    $spf->setText($string);

    return $spf;
};

$customHandlers = ['SPF' => $spf];

$record = 'example.com. 7200 IN SPF "v=spf1 a mx ip4:69.64.153.131 include:_spf.google.com ~all"';
$parser = new \Badcow\DNS\Parser\Parser($customHandlers);
$zone = $parser->makeZone('example.com.', $record);

You can also overwrite the default handlers if you wish, as long as your handler method returns an instance of Badcow\DNS\Rdata\RdataInterface.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].