Last active
September 12, 2023 04:08
-
-
Save dyeo/abbad9e532419960356d2ec3becbc470 to your computer and use it in GitHub Desktop.
ipview: quick and dirty ip and mac address grab command for windows. put in a path dir and you're good to go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0ipview.ps1" %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Adapters = Get-NetAdapter | Where-Object { $_.Status -ne 'Disabled' } | |
Write-Host "" | |
foreach ($Adapter in $Adapters) | |
{ | |
$MACAddressRaw = $Adapter.MacAddress | |
if (![string]::IsNullOrWhiteSpace($MACAddressRaw)) { | |
$MACAddress = ($MACAddressRaw -replace '[^0-9A-Fa-f]', '') -replace '(.{2})', '$1:' | |
$MACAddress = $MACAddress.TrimEnd(':') | |
} else { | |
$MACAddress = $null | |
} | |
$IPConfig = Get-NetIPAddress -InterfaceIndex $Adapter.IfIndex | |
$IPAddress = $IPConfig | Where-Object { $_.AddressFamily -eq 'IPv4'} | Select-Object -ExpandProperty IPAddress -First 1 | |
if (![string]::IsNullOrWhiteSpace($MACAddress) -or ![string]::IsNullOrWhiteSpace($IPAddress)) | |
{ | |
Write-Host "$($Adapter.Name):" | |
Write-Host " MAC Address . . . . : $MACAddress" | |
Write-Host " IP Address. . . . . : $IPAddress" | |
Write-Host "" | |
} | |
} | |
try { | |
$PublicIP = Invoke-RestMethod -Uri 'https://api.ipify.org?format=json' -TimeoutSec 10 | Select-Object -ExpandProperty ip | |
} | |
catch { | |
$PublicIP = "" | |
} | |
Write-Host "Public IP Address: $PublicIP" | |
Write-Host "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment