Powershell快速获取IP地址 1


你可以这样列出本机电脑的MAC和IP地址:

#requires -Version 3

$ComputerName = ''

[System.Net.Dns]::GetHostAddresses($ComputerName).IPAddressToString 

如果只需要IPV4地址:

#requires -Version 1

$ComputerName = ''

[System.Net.Dns]::GetHostAddresses($ComputerName) |
Where-Object {
  $_.AddressFamily -eq 'InterNetwork' 
} |
Select-Object -ExpandProperty IPAddressToString

同样,可以获取IPV6地址:


$ComputerName = ''

[System.Net.Dns]::GetHostAddresses($ComputerName) |
Where-Object {
  $_.AddressFamily -eq 'InterNetworkV6' 
} |
Select-Object -ExpandProperty IPAddressToString

原文地址:Quickly Getting IP Addresses

×用微信扫描并分享
本文链接: https://www.pstips.net/quickly-getting-ip-addresses.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

一条评论 “Powershell快速获取IP地址