GithubHelp home page GithubHelp logo

arteyazilim / dns Goto Github PK

View Code? Open in Web Editor NEW

This project forked from badcow/dns

0.0 1.0 0.0 295 KB

This PHP library constructs DNS zone records based on RFC1035 and subsequent standards.

License: MIT License

PHP 100.00%

dns's Introduction

Badcow DNS Zone 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.

Build Status

Build Status Code Coverage Scrutinizer Code Quality

Example usage

require_once __DIR__ . '/vendor/autoload.php';

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->setRdata(Factory::Soa(
    'example.com.',
    'post.example.com.',
    '2014110501',
    3600,
    14400,
    604800,
    3600
));

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

$ns2 = new ResourceRecord;
$ns2->setName('@');
$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.'));

$loc = new ResourceRecord;
$loc->setName('canberra');
$loc->setRdata(Factory::Loc(
    -35.3075,   //Lat
    149.1244,   //Lon
    500,        //Alt
    20.12,      //Size
    200.3,      //HP
    300.1       //VP
));
$loc->setComment('This is Canberra');

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

echo AlignedBuilder::build($zone);

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   IN A    192.168.1.42; This is a local ip.

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

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

; LOC RECORDS
canberra     IN LOC  (
                     35 18 27.000 S ; LATITUDE
                     149 7 27.840 E ; LONGITUDE
                     500.00m        ; ALTITUDE
                     20.12m         ; SIZE
                     200.30m        ; HORIZONTAL PRECISION
                     300.10m        ; VERTICAL PRECISION
                     ); This is Canberra

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
canberra  IN LOC 35 18 27.000 S 149 7 27.840 E 500.00m 20.12m 200.30m 300.10m; This is Canberra
@  IN MX 20 mail-gw2.example.net.
@  IN SOA example.com. post.example.com. 2014110501 3600 14400 604800 3600
@  IN NS ns1.nameserver.com.
@  IN MX 30 mail-gw3.example.net.
sub.domain  IN A 192.168.1.42; This is a local ip.
ipv6.domain  IN AAAA ::1; This is an IPv6 domain.
@  IN NS ns2.nameserver.com.
@  IN MX 10 mail-gw1.example.net.

Supported Types

  • A
  • AAAA
  • APL
  • CNAME
  • CAA
  • DNAME
  • HINFO
  • LOC
  • MX
  • NS
  • PTR
  • SOA
  • SRV
  • TXT
  • DNSSEC specific types:
    • DNSKEY
    • DS
    • NSEC
    • RRSIG

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.