Skip to content

Instantly share code, notes, and snippets.

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