Skip to content

freerk/hosts-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.toJSON()

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

What is the Hosts file

hosts (file)

License

the MIT License.

About

hosts file parser

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.7%
  • Makefile 1.3%