0.3.2 • Published 10 years ago

hosts-parser v0.3.2

Weekly downloads
42
License
MIT
Repository
github
Last release
10 years ago

hosts-parser

hosts file parser

Build Status

Usage

var fs = require('fs');
var Hosts = require('hosts-parser').Hosts;
var hosts = new Hosts(fs.readFileSync('/etc/hosts', 'utf8'));
console.log(hosts.toJSON());
/**
[
    {
        "ip": "127.0.0.1",
        "hostname": "localhost"
    }
]
**/
console.log(hosts.resolve('localhost'));
// 127.0.0.1

API

Hosts(hosts) and Hosts.prototype.parse(hosts)

var file = fs.readFileSync('/etc/hosts', 'utf-8');
var hosts = new Hosts(file);
// or (new Hosts()).parse(file);
// return a parsed Hosts object

Hosts.prototype.resolve(hostname)

hosts.resolve(hostname);
// return the ip or undefined

Hosts.prototype.reverse(ip)

hosts.reverse(ip);
// return the hostname or undefined

Hosts.prototype.reverse(ip, callback)

hosts.reverse(ip, function (err, hostname) {
  // pass the hostname or a NotFound Error
});

Hosts.prototype.toJSON()

hosts.toJSON();
// return a json formatted object

What is the Hosts file

hosts (file)

License

the MIT License.

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago