$ 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
系统hosts路径
path default: HostAdmin.OS_HOST
path default: HostAdmin.OS_HOST
host.add({
text : '#comment line'
});
hosts:
#comment line
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
#====
hosts:
#comment
#comment line
host.remove({
text : '#comment line'
});
hosts:
#comment
不会删除组内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
#====
不会改变组内
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
#====
MIT license