本文介绍了有没有一种方法可以从IP地址获取主机名而不依赖DNS查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本,该脚本依赖于了解网段中计算机的名称,但是我发现的所有脚本都依赖于DNS查询,该DNS查询仅使用一些计算机的名称进行答复.例如:

I'm trying to write a script that depends on knowing the names of the computers on a network segment, but all the scripts I've found depend on a DNS inquiry which only replys with the names of a few of the machines. For example:

[System.Net.Dns]::GetHostbyAddress($IPAddress) 

我也尝试使用

Ping -a $ipaddress

,但这通常也无法返回计算机名称.有没有办法直接询问主机的名称,以及在AD中可能需要什么级别的权限才能获得响应?
预先感谢.

but this often fails to return the machine name as well. Is there a way to ask the host what it's name is directly and what level of permissions might be required in AD to get a response?
Thanks in advance.

推荐答案

[System.Net.DNS]::GetHostByAddress()(现在为[System.Net.DNS]::GetHostEntry())尽管有名称,但不仅依赖DNS.它还将检查本地C:\Windows\System32\Drivers\etc\hosts文件中是否有本地配置的条目.

[System.Net.DNS]::GetHostByAddress() (now [System.Net.DNS]::GetHostEntry()) doesn't only rely on DNS, despite it's name. It will also check the local C:\Windows\System32\Drivers\etc\hosts file for locally configured entries.

直dns找不到名称:

PS C:\Users\Tim> nslookup 192.168.1.50
Server:  dns03
Address:  192.168.2.103

*** rpi03 can't find 192.168.1.50: Non-existent domain

但是,gethostentry()仍然找到名称:

yet, gethostentry() still finds the name:

PS C:\Users\Tim> [system.net.dns]::gethostentry('192.168.1.50')

HostName  Aliases AddressList
--------  ------- -----------
localentry {}      {192.168.1.50}

这篇关于有没有一种方法可以从IP地址获取主机名而不依赖DNS查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:20