New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

hostify

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hostify

CLI tool and utils for hosts files: /etc/hosts and C:\Windows\System32\drivers\etc\hosts

latest
Source
npmnpm
Version
0.3.0-beta.1
Version published
Maintainers
1
Created
Source

Build Status Coverage Status NPM version js-standard-style

Hostify

Icon

Hostify is a module that help us to work with the hosts file of our operating system.

It supports both a CLI tool and a module you can use in your own project.

NOTE: library in progress. Please use with caution and report any issue on here: https://github.com/eridem/hostify/issues

CLI tool operations

# Usage
hostify [COMMAND] [OPTIONS]

# For help
hostify --help
hostify [COMMAND] --help
CommandDescriptionExample
listShow all entries in the host filehostify list
list --ipFilterExp "REGEXP"Show entries which IPs match with RegExphostify list --ipFilterExp ".*\.255"
list --hostFilterExp "REGEXP"Show entries which Host match with RegExphostify list --hostFilterExp ".*tracking.*"
list --ipFilterExp "REGEXP" --hostFilterExp "REGEXP"Show entries which IP and Host match with both each RegExphostify list --ipFilterExp "0.0.0.0" --hostFilterExp ".*tracking.*"
add --ip "IP" --host "HOST" [--comment "COMMENT"]Add a single entry to the hosts filehostify add --ip "0.0.0.0" --host "tracking.localhost" --comment "Tracking entry"
delete --ipFilterExp "REGEXP" [--what-if]Delete entries which IPs match with RegExphostify delete --ipFilterExp "127.0.0.\d+"
delete --hostFilterExp "REGEXP" [--what-if]Delete entries which Host match with RegExphostify delete --hostFilterExp ".*project\.local"

Special options

OptionDescriptionExample
--pathSpecify path of another hosts filehostify list --path ./my-hosts.txt

Module interface

Import module with:

const hostify = require('hostify').operations

List

hostify.list(options): <Array>{ ip: string, host: string }`

Show entries in the host file.

OptionModelDefault
filterIpFnfilterIpFn: (val: string) => boolean(v) => true
filterHostFnfilterHostFn: (val: string) => boolean(v) => true
pathpath: stringOS hosts path
const options = {
  filterIpFn: (val) => val.endsWith('.255'),       // Filter IPs
  filterHostFn: (val) => val.contains('tracking')  // Filter Hosts
  // path: './my-hosts-file.txt'                   // Hosts file
}

const entries = hostify.list(options)

entries.forEach(entry => console.log(entry.ip, entry.host, entry.comment))

Add

hostify.add(options): <Array>{ ip: string, host: string }

Add entries in the host file.

OptionModelDefault
entries<Array>{ ip: string, host: string, comment: string }null
pathpath: stringOS hosts path
const options = {
  entries: [                                       // Entries to add
    { ip: '0.0.0.0', host: 'ad.localhost' },
    { ip: '0.0.0.0', host: 'tracking.localhost', comment: 'Track entry' }
  ],
  // path: './my-hosts-file.txt'                   // Hosts file
}

const entries = hostify.add(options)

entries.forEach(entry => console.log(entry.ip, entry.host, entry.comment))

Delete

hostify.delete(options): <Array>{ ip: string, host: string }

Delete entries in the host file.

OptionModelDefault
filterIpFnfilterIpFn: (val: string) => boolean(v) => true
filterHostFnfilterHostFn: (val: string) => boolean(v) => true
whatIfwhatIf: booleanfalse
pathpath: stringOS hosts path
const options = {
  filterIpFn: (val) => val.endsWith('.255'),       // Filter IPs
  filterHostFn: (val) => val.contains('tracking'), // Filter Hosts
  whatIf: true                                     // Do not execute delete operation, only obtain results
  // path: './my-hosts-file.txt'                   // Hosts file
}

const entries = hostify.delete(options)

entries.forEach(entry => console.log(entry.ip, entry.host, entry.comment))

Keywords

hosts

FAQs

Package last updated on 25 Feb 2017

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