龙空技术网

powershell 获取ip、dns、mac地址、网关信息

洲游历累 140

前言:

如今同学们对“netipaddress”大约比较注重,同学们都想要剖析一些“netipaddress”的相关资讯。那么小编也在网上网罗了一些有关“netipaddress””的相关资讯,希望兄弟们能喜欢,你们快快来学习一下吧!

1.将以下代码保存为ps.ps1

$nic=((gwmi Win32_NetworkAdapter -filter 'netconnectionid is not null').netconnectionid  | select-object -First 1)$ip=(Get-NetAdapter -Name $nic | Get-NetIPAddress).IPv4Address$dns=(Get-NetAdapter -Name $nic | Get-DnsClientServerAddress -AddressFamily IPv4 | select ServerAddresses).ServerAddresses$gateway=(Get-NetAdapter -Name $nic | Get-NetIPConfiguration | ForEach-Object { $_.IPv4DefaultGateway } | select NextHop).NextHop$macAddress=(Get-NetAdapter -Name $nic | select MacAddress).MacAddressWrite-Output "{`"nic`":`"$nic`",`"ip`":`"$ip`",`"dns`":`"$dns`",`"gateway`":`"$gateway`",`"macAddress`":`"$macAddress`"}"

2.powershell中执行如下结果

标签: #netipaddress