All Projects → feross → Hostile

feross / Hostile

Licence: mit
Simple, programmatic `/etc/hosts` manipulation (in node.js)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Hostile

Polish Ads Filter
CertyficateIT - Oficjalne polskie filtry do Adblock, uBlock Origin, Adguard
Stars: ✭ 462 (-29.36%)
Mutual labels:  hosts
Google Access Helper
谷歌访问助手破解版、谷歌翻墙、谷歌梯子、谷歌梯子扩展工具、谷歌商店访问、Chrome翻墙
Stars: ✭ 505 (-22.78%)
Mutual labels:  hosts
Surge Hosts
hosts for surge,翻墙,强力去APP广告,google,facebook,twitter,youtube,etc
Stars: ✭ 577 (-11.77%)
Mutual labels:  hosts
Cnp3
Computer Networking : Principles, Protocols and Practice (first and second edition, third edition is being written on https://github.com/cnp3/ebook)
Stars: ✭ 471 (-27.98%)
Mutual labels:  ip
Blacklist
Curated and well-maintained hostfile to block ads, tracking, cryptomining, and more! Updated regularly. ⚡🔒
Stars: ✭ 492 (-24.77%)
Mutual labels:  hosts
Proxyiplib
全球免费代理IP库,高可用IP,精心筛选优质IP,2s必达
Stars: ✭ 521 (-20.34%)
Mutual labels:  ip
Information collection handbook
Handbook of information collection for penetration testing and src
Stars: ✭ 447 (-31.65%)
Mutual labels:  ip
Adhosts
手机电脑去广告 hosts&规则 PC&Android
Stars: ✭ 607 (-7.19%)
Mutual labels:  hosts
Request Ip
A Node.js module for retrieving a request's IP address on the server.
Stars: ✭ 501 (-23.39%)
Mutual labels:  ip
Qqwry.dat
自动更新的纯真ip库,每天自动更新
Stars: ✭ 559 (-14.53%)
Mutual labels:  ip
Cuteit
IP obfuscator made to make a malicious ip a bit cuter
Stars: ✭ 475 (-27.37%)
Mutual labels:  ip
Ipv6 Hosts
Fork of https://code.google.com/archive/p/ipv6-hosts/, focusing on automation
Stars: ✭ 4,408 (+574.01%)
Mutual labels:  hosts
Nali
An offline tool for querying IP geographic information and CDN provider.一个查询IP地理信息和CDN服务提供商的离线终端工具.
Stars: ✭ 535 (-18.2%)
Mutual labels:  ip
Virtual Hosts
hosts for android,implement by vpn mode,supports wildcard DNS records
Stars: ✭ 465 (-28.9%)
Mutual labels:  hosts
Cidranger
Fast IP to CIDR lookup in Golang
Stars: ✭ 586 (-10.4%)
Mutual labels:  ip
Hosts
镜像:https://scaffrey.coding.net/p/hosts/git / https://git.qvq.network/googlehosts/hosts
Stars: ✭ 20,788 (+3078.59%)
Mutual labels:  hosts
Hosts For Surge
🌟 Hosts for Internet Freedom
Stars: ✭ 514 (-21.41%)
Mutual labels:  hosts
Hiproxy
🛠 hiproxy is a lightweight proxy tool for Front-End developers based on Node.js that supports an NGINX-like configuration. 🔥
Stars: ✭ 629 (-3.82%)
Mutual labels:  hosts
Ultimate.hosts.blacklist
The Ultimate Unified Hosts file for protecting your network, computer, smartphones and Wi-Fi devices against millions of bad web sites. Protect your children and family from gaining access to bad web sites and protect your devices and pc from being infected with Malware or Ransomware.
Stars: ✭ 606 (-7.34%)
Mutual labels:  hosts
Ip Location Zh
获取 IP 地址的真实地理位置
Stars: ✭ 556 (-14.98%)
Mutual labels:  ip

hostile travis npm downloads javascript style guide

Simple, programmatic /etc/hosts manipulation (in node.js)

hostile

install

npm install hostile

usage

If you use OS X or Linux, this module assumes your hosts file is at /etc/hosts. On Windows, it assumes your hosts file is at C:/Windows/System32/drivers/etc/hosts.

Commands that modify the hosts file require root privileges.

list all host file records

hostile list

set a domain in the hosts file

hostile set [ip] [host]

examples:

hostile set localhost domain.com
hostile set 192.168.33.10 domain.com

remove a domain from the hosts file

hostile remove [host]

example:

hostile remove domain.com

load a set of hosts from a file

hostile load [file_path]

hosts.txt

# hosts.txt
127.0.0.1 github.com
127.0.0.1 twitter.com

example:

hostile load hosts.txt

unload [remove] a set of hosts from a file

hostile unload [file_path]
# hosts.txt
127.0.0.1 github.com
127.0.0.1 twitter.com

example:

hostile unload hosts.txt

methods

Commands that modify the hosts file require root privileges.

I wouldn't recommend running your production node server with admin privileges unless you downgrade to a normal user with process.setuid(id) before you start accepting requests.

All methods have sync versions. Just omit the callback parameter.

add a rule to /etc/hosts

var hostile = require('hostile')
hostile.set('127.0.0.1', 'peercdn.com', function (err) {
  if (err) {
    console.error(err)
  } else {
    console.log('set /etc/hosts successfully!')
  }
})

If the rule already exists, then this does nothing.

remove a rule from /etc/hosts

hostile.remove('127.0.0.1', 'peercdn.com', function (err) {
  if (err) {
    console.error(err)
  } else {
    console.log('set /etc/hosts successfully!')
  }
})

If the rule does not exist, then this does nothing.

get all lines in /etc/hosts

// If `preserveFormatting` is true, then include comments, blank lines and other
// non-host entries in the result
var preserveFormatting = false

hostile.get(preserveFormatting, function (err, lines) {
  if (err) {
    console.error(err.message)
  }
  lines.forEach(function (line) {
    console.log(line) // [IP, Host]
  })
})

get all lines in any file

// If `preserveFormatting` is true, then include comments, blank lines and other
// non-host entries in the result
var preserveFormatting = false

hostile.getFile(file_path, preserveFormatting, function (err, lines) {
  if (err) {
    console.error(err.message)
  }
  lines.forEach(function (line) {
    console.log(line) // [IP, Host]
  })
})

contributors

license

MIT. Copyright (c) Feross Aboukhadijeh.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].