检索DNS响应

时间:2019-04-29 19:34:48

标签: shell powershell

作为Shell或Powershell脚本开发的一部分,我需要一条指令,允许我在变量中检索给定站点的IP地址。 无论是外壳还是Powershell,请帮助我

1 个答案:

答案 0 :(得分:0)

在powershell中,您可以使用

[System.Net.DNS]::GetHostAddresses("www.mydns.org")[0].IpAddressToString

GetHostAddresses可能返回多个IP地址。 [0]返回第一个。 IpAddressToString获取地址的通用表示形式(例如63.251.171.81)