以编程方式添加主机(Windows 下的名称解析)

发布于 2024-07-14 17:49:03 字数 353 浏览 2 评论 0原文

我想以编程方式向 Windows 添加名称/IP 关联,以便可以在本地解析该名称。 这不必在重新启动之间持续存在。

我现在唯一的方法是向“hosts”文件添加一个条目,但这感觉很奇怪,特别是因为我想自动化它。

有没有办法使用命令行工具或 Win32 API 来执行此操作? 也许通过向 Windows DNS 缓存添加一个条目或类似的东西?

哦,请说明该解决方案是否兼容 Vista。

问候。

编辑:谢谢,伙计。 遗憾的是,您的所有答案确实涉及 DNS 或其他服务器。 我一直在寻找一个可以在“标准”Windows 安装上运行的纯本地解决方案。 但这样的事情似乎并不存在。

I would like to programmatically add to Windows a name / IP association so that this name can be resolved locally. This does not have to be persisted between reboots.

The only way I now is to add an entry to the "hosts" file, but this feels hacky especially since I would like to automate this.

Is there any way to do this using a command-line tool or a Win32 API? Perhaps by addind an entry to Windows DNS cache or something similar?

Oh, and please state if this solution is Vista-compatible.

Regards.

Edit : Thanks, guy. Sadly, all of your answers indeed involve DNS or other servers. I was looking for a purely local solution which would work on a "standard" Windows installation. Such a thing does not seem to exist, though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光沙漏 2024-07-21 17:49:03

此页面列出了一堆脚本使用 DNS 服务执行各种操作,包括为其添加名称。 这似乎是 Windows Management Instrumentation系统,恐怕我对此一无所知。

编辑:还有此功能,它说它可以向 DNS 添加记录。 不确定这是否意味着它实际上修改了 DNS 服务器的状态,或者是否涉及本地解析器。 它还需要 Windows 2000 Server 或更高版本,因此它可能太窄了。

This page lists a bunch of scripts for doing various things with the DNS service, including adding a name to it. This seems to be part of the Windows Management Instrumentation system, which I'm afraid I don't know anything about.

EDIT: There is also this function, which says it can add records to the DNS. Not sure if that means that it actually modifies the DNS server's state, or if it talks about the local resolver. It also requires Windows 2000 Server or greater, so it might be too narrow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文