Converting Binary Data to IP Address (and vice versa)

by May 28, 2013

In a previous tip we showed how you can display an IPv4 address as a binary. Here's an even faster (and more cryptic) way:

$ipV4 = '192.168.12.33'
[Convert]::toString(([IPAddress][String]([IPAddress]$ipV4).Address).Address,2)

The result looks like this:

Now how would you do the opposite and turn a binary into an IP address? Here's how:

$IPBinary = '11000000101010000000110000100001'
([System.Net.IPAddress]"$([System.Convert]::ToInt64($IPBinary,2))").IPAddressToString

Twitter This Tip! ReTweet this Tip!