Unix command “host” - is there Windows equivalent?

爷,独闯天下 提交于 2019-12-09 07:57:09

问题


I am on a Windows 7 machine and I was instructed to use the Unix command "host" as per this article:

https://devcenter.heroku.com/articles/custom-domains

however, host is not a valid command with Windows and even with bash on Windows I could find host installed.

Is there a Windows equivalent to "host"?


回答1:


This question is more suited to Super User, but the command you're looking for is nslookup. Both are (at their most basic) used to look up IP addresses for hostnames. You can run cmd and do nslookup hostname the same way you'd do host hostname. If you need something other than the IP address, the command-line arguments will differ. Run nslookup with no arguments and type help at the prompt for details.




回答2:


Although you will be able to find the DNS resolution using nslooukup, there is no direct equivalent to the host command in Windows. There is a similar question on Super User.




回答3:


Old thread, but I hit it doing Google searches. There is no built in but if you add this to your profile.ps1 it'll do what you want.

function host {
param ($ip)
$ErrorActionPreference='stop'
$answer=Resolve-DnsName $ip
if ($answer[0].IPAddress -eq $null)
{
    echo "$($answer.Name[0]) has address $($answer.namehost[0])"
}
else
{
    echo "$($answer.Name[0]) has address $($answer.Ipaddress[0])"
}
}


来源:https://stackoverflow.com/questions/21520191/unix-command-host-is-there-windows-equivalent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!