host java_Java修改Hosts文件——HostUtils.java

read() {

return Arrays.stream(LocalFileIOUtils.getInstance().read(HOSTS_PATH).split(ENDL))

.filter(it->!it.trim().matches("(^#.*)|(\\s*)"))

.map(it->it.replaceAll("#.*", "").trim().replaceAll("\\s+", "\t"))

.collect(Collectors.toSet());

}

public static boolean append(String ip, String url) {

Setsets = HostUtils.read();

sets.add(String.format("%s\t%s", ip, url));

return LocalFileIOUtils.getInstance().write(HOSTS_PATH, sets.stream().collect(Collectors.joining(ENDL))) && flushdns();

}

public static boolean exists(String ip, String url) {

return HostUtils.read().contains(String.format("%s\t%s", ip, url));

}

public static boolean flushdns() {

try {

Runtime.getRuntime().exec("ipconfig /flushdns");

return true;

} catch (IOException e) {

e.printStackTrace();

return false;

}

}

public static void main(String[] args) {

int nThreads = 16;

ExecutorService executorService = Executors.newCachedThreadPool();

while (nThreads-- > 0) {

executorService.execute(()->{

boolean rst = HostUtils.append("0.0.0.0", "www.baidu.com");

System.out.println(rst);

HostUtils.read().forEach(System.out::println);

});

}

executorService.shutdown();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用TCL语法将InternetGatewayDevice.LANDevice.1.Hosts.Host.1.IPAddress 192.168.254.100 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.AddressSource Static InternetGatewayDevice.LANDevice.1.Hosts.Host.1.LeaseTimeRemaining 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.MACAddress 28:d2:44:ae:2c:95 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.HostName unknown28d244ae2c95 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.InterfaceType Ethernet InternetGatewayDevice.LANDevice.1.Hosts.Host.1.Layer2Interface InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.4 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.Active 1 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.X_0000C5_LastActive Thu Jan 1 00:20:53 1970 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.IPv6AddressNumberOfEntries 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.IPAddress 192.168.254.10 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.AddressSource DHCP InternetGatewayDevice.LANDevice.1.Hosts.Host.2.LeaseTimeRemaining 2591999 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.MACAddress 6c:63:9c:08:24:62 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.HostName x5042-2460 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.InterfaceType 802.11 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Layer2Interface InternetGatewayDevice.LANDevice.1.WLANConfiguration.8 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Active 1 InternetGatewayDevice.LANDevice.1.Hosts.Host.3.Active 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.3.AddressSource DHCP中的IP地址192.168.254.10取出
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值