使用 PowerShell 从主机名解析 IP 地址 [英] Resolving IP Address from hostname with PowerShell

查看:77
本文介绍了使用 PowerShell 从主机名解析 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Powershell 从主机名中获取 ipaddress,但我真的不知道如何.

I am trying to get the ipaddress from a hostname using Powershell, but I really can't figure out how.

有什么帮助吗?

推荐答案

您可以通过 GetHostAddresses 像这样:

You can get all the IP addresses with GetHostAddresses like this:

$ips = [System.Net.Dns]::GetHostAddresses("yourhosthere")

你可以像这样迭代它们:

You can iterate over them like so:

[System.Net.Dns]::GetHostAddresses("yourhosthere") | foreach {echo $_.IPAddressToString }

一个服务器可能有多个 IP,因此这将返回一组 IP.

A server may have more than one IP, so this will return an array of IPs.

这篇关于使用 PowerShell 从主机名解析 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆