trying to convert a Mac address to an Ipv6 link-local address. basically doing this ( ref https://ben.akrin.com/?p=1347) in powershell.
take the mac address: for example 52:74:f2:b1:a8:7f
throw ff:fe in the middle: 52:74:f2:ff:fe:b1:a8:7f
reformat to IPv6 notation 5274:f2ff:feb1:a87f
convert the first octet from hexadecimal to binary: 52 -> 01010010
invert the bit at index 6 (counting from 0): 01010010 -> 01010000
convert octet back to hexadecimal: 01010000 -> 50
replace first octet with newly calculated one: 5074:f2ff:feb1:a87f
prepend the link-local prefix: fe80::5074:f2ff:feb1:a87f
done!
Note the that IPV6 address obtained by the ipconfig / Get-NetIPAddress are not suitable for my needs, these address obfuscate the Mac address. I got starting by getting the Mac I am interested in. I am parsing WDS network unlock logs and want to identify source computer. The WDS logs are obtained in this manner $WDSEventsVerbose = Get-WinEvent -cn $WDS -EA silentlycontinue -FilterHashtable @{ProviderName="Microsoft-Windows-Deployment-Services-Diagnostics";ID=32769,32768,24581;StartTime=$(get-date).AddMinutes(-$MinToQuery)}
Any suggestions on how to convert my $RemoteMacaddress variable to ipv6 link notation. Regex search and replace would be too complex for me how would you approach the problem ?
That is a lot of work just to do this. Well, depending on what PowerShell version and OS version you are doing this against.
Just work with the raw cmdlets and combine the data points.
# Get IPv4 Address and Mac address
Get-WmiObject win32_networkadapterconfiguration `
| Select-Object -Property @{name='IPAddress';Expression={($_.IPAddress[0])}},MacAddress `
| Where IPAddress -NE $null
# Get IPv6 Address and Mac address
Get-WmiObject win32_networkadapterconfiguration `
| Select-Object -Property @{name='IPAddress';Expression={($_.IPAddress[1])}},MacAddress `
| Where IPAddress -NE $null
# Get address family information IPv4
Get-NetNeighbor -AddressFamily IPv4
# Get address family information IPv6
Get-NetNeighbor -AddressFamily IPv6
I agree simple is better but in this case it does not work,
The WDS Bitlocker network unlock logs show the IPv6 Link local address of the physical device when the client PC is booting, and it the PC’s UEFI bios that send’s out the Network unlock request. in this example the WDS server show a log entry such as :
Therefore if I want to parse the WDS log files to identify each PC in the logs I need to construct the IPv 6 address using the EUI-64 method. Can’t rely on the windows randomly generated IPV6 address.