October 2017
Intermediate to advanced
440 pages
11h 47m
English
The following function uses the System.Net.NetworkInformation namespace to discover IPv4 address information. This allows us to return the same thing whether it is run on Windows or Linux.
If it were Windows only, we might have used WMI or the Get-NetIPConfiguration command. Creating something to work on both operating systems is more challenging:
function Get-IPConfig { [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | ForEach-Object { $ipProperties = $_.GetIPProperties() $addresses = $ipProperties.UnicastAddresses | Where-Object { $_.Address.AddressFamily -eq 'InterNetwork' } | ForEach-Object { "$($_.Address) $($_.IPv4Mask)" } $gateway = $ipProperties.GatewayAddresses.Address | Where-Object { $_.AddressFamily ...Read now
Unlock full access