Skip to content

Instantly share code, notes, and snippets.

@Axlfc
Created October 23, 2024 07:05
Show Gist options
  • Save Axlfc/1a2d7ff490f1a01cb7109d7ed9560c34 to your computer and use it in GitHub Desktop.
Save Axlfc/1a2d7ff490f1a01cb7109d7ed9560c34 to your computer and use it in GitHub Desktop.
function Get-WifiIPAddress {
try {
# Get network adapters with Wi-Fi in their description
$adapters = Get-NetAdapter | Where-Object { $_.InterfaceDescription -like '*Wi-Fi*' }
if ($adapters.Count -eq 0) {
Write-Error "No Wi-Fi adapter found."
return $null
}
# Get the first Wi-Fi adapter
$wifiAdapter = $adapters[0]
# Get the IP address associated with the Wi-Fi adapter
$ipAddress = (Get-NetIPAddress -InterfaceIndex $wifiAdapter.InterfaceIndex -AddressFamily IPv4).IPAddress
if ($ipAddress) {
return $ipAddress
} else {
Write-Error "No IP address found for the Wi-Fi adapter."
return $null
}
} catch {
Write-Error "Failed to retrieve Wi-Fi adapter IP address."
}
}
# Call the function and output the IP address
$ipAddress = Get-WifiIPAddress
if ($ipAddress) {
Write-Host "Your Wi-Fi IP Address is: $ipAddress"
$Age = Read-Host "IP Address"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment