New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hosts-parser

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hosts-parser

hosts file parser

  • 0.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

Keywords

FAQs

Package last updated on 24 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc