Coder Social home page Coder Social logo

host-admin's Introduction

Host-admin

快速开始

$ npm install host-admin -g
var HostAdmin = require('host-admin');
var host = HostAdmin();

hosts:

127.0.0.1 www.admin.com

打开hosts文件

//系统hosts文件
host.readFile();
//or
//指定文件
host.readFile('/myHostPath/hosts');

添加一个配置

host.add({
    ip : '127.0.0.1',
    domain : 'local.host.com',
    comment : 'comment'
});

写入hosts文件

//系统hosts文件
host.writeFile();
//指定文件
var path = '/myHostPath/hosts'
host.writeFile(path);

hosts:

127.0.0.1 local.host.com #comment

HostAdmin.OS_HOST

系统hosts路径

.readFile([path])

path default: HostAdmin.OS_HOST

.writeFile([path])

path default: HostAdmin.OS_HOST

.add(setOption)

添加注释行

host.add({
	text : '#comment line'
});

hosts:

 #comment line

添加ip

host.add({
    ip : '127.0.0.1',
    domain : 'local.host.com',
    comment : 'comment'
    enable : false
});

hosts:

 #127.0.0.1 local.host.com #comment

添加分组

host.add({
	group : 'new group'
});

hosts:

 #==== new group  
 #====

组内添加

如果分组不存在会自动添加分组

host.add({
	group : 'new group',
    ip : '127.0.0.1',
    domain : 'local.host.com'
});

hosts:

 #==== new group  
 127.0.0.1 local.host.com
 #====

.remove(filter)

删除注释行

hosts:

 #comment
 #comment line
host.remove({
	text : '#comment line'
});

hosts:

 #comment

删除ip

不会删除组内ip
hosts:

 127.0.0.1 local.host.com
 #==== group
 127.0.0.1 local.host.com
 #====
host.remove({
    ip : '127.0.0.1',
    domain : 'local.host.com'
});

hosts:

 #==== group
 127.0.0.1 local.host.com
 #====

删除分组

host.add({
	group : 'new group'
});

组内删除

hosts:

 127.0.0.1 local.host.com
 #==== group
 127.0.0.1 local.host.com
 #====
host.remove({
	group : 'new group',
    ip : '127.0.0.1',
    domain : 'local.host.com'
});

hosts:

 127.0.0.1 local.host.com
 #==== group
 #====

.change(filter, setOption)

修改

不会改变组内
hosts:

 127.0.0.1 local.host.com
 #==== group
 127.0.0.1 local.host.com
 #====

code

host.change({
    ip : '127.0.0.1',
    domain : 'local.host.com'
}, {
    ip : '8.8.8.8'
})

hosts:

 8.8.8.8 local.host.com
 #==== group
 127.0.0.1 local.host.com
 #====

修改组内

可以直接设置组名 hosts:

 127.0.0.1 local.host.com
 #==== group
 127.0.0.1 local.host.com
 #====

code

host.change({
    group : 'group',
    ip : '127.0.0.1',
    domain : 'local.host.com'
}, {
    name : 'change name',
    ip : '8.8.8.8'
})

hosts:

 127.0.0.1 local.host.com
 #==== change name
 8.8.8.8 local.host.com
 #====

License

MIT license

host-admin's People

Contributors

crazybear avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.