LAPS Winform

*UPDATE*

I have created the *final* iteration of this WPF form which can be found here

*UPDATE*

I didn’t like having to remote desktop into my domain controller and couldn’t figure out if there was a LAPS tool included in RSAT tools so I decided just to make my own and to add some extra features.

I wanted the GUI to look pretty much identity to the actual LAPS GUI. You can see the difference below:

You might be able to see that I  changed the “Set” button to say “Set and Update”. This was because I wanted the form to also attempt to update the group policy settings on the computer so that it would get a new password a lot quicker than the original GUI.

There’s not much else I can say, I will leave the entire script below for you to copy and paste. You will need to add the domain controller for your environment in the $domaincontroller variable at the top of the script. I have converted this to an EXE and run whenever I need it, never skips a beat. Let me know how you get on with it. Enjoy!

#ADDING FORM ASSEMBLY
Add-Type -AssemblyName system.windows.forms

#ENTER DOMAIN CONTROLLER BELOW
$domaincontroller = ""

#BASE 64 ICON
[string]$icon64 = "iVBORw0KGgoAAAANSUhEUgAAAEEAAAA5CAYAAABphkbpAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAB5kSURBVGhDpXt5cFXHne7j/TN/vKr33lRsa7lXV9KV7r3S1b1akcCAQWKXQEK7hAQICSTATjI1M37UeItdFY8dO2MncVyVpTLjmedZY7ABLYCIoTLl2PFCbLzFjrFjs9gGHmDQvn7v+37nHFkEucr2NPTtc0736e7f17+1++i/YXYaHeHPlJuBCeZJu2KaZtbNOLOqdT/FH5VeZpqcdt61ujH2MMn7KeVJNpni6xNeU7cPjjMxZc003jifaRhrM9O/+pxi/RTG7H3nHtNq6V67eXpKvXxx/RTrx6ZHeU1CxodZAteCMDHICXCo6TEONMFm+uXjKZdyTUoFidJEpt1BJidV2pXz3M0aUE91PW7Td/5Nqk6kijjLbDY7CxGVHggTzvh6U0BMTrv9zozv1Hv3M+N+Qb3lEQIwLDCuA2GI1XpBaI9rmpa9Z5rQNCdo8+OvSu/aS5qABtNERbwIdqG0fPzF5/F///5n+Nt77sQ9t/8VHn/oQez5x3/Eh2//ntUczSV8etopLXtgMHmc5hCk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W1QxV2sYjS7HnKJ/pXoiqQ2/Wo7ywkvVaDYXLaqc/uNJz5imxvp6LlfWesmanTK6bpl4yNla/xkVeZgOJmvrzxjd2Z6m+rR/+2Htu9voxWpj1js2L2cRc/QL/H9J7FoQajQSGAAAAAElFTkSuQmCC"

#CONVERTING BASE 64 ICON TO SOMETHING USEFUL
$iconstream = [System.IO.MemoryStream][System.Convert]::FromBase64String($icon64)
$iconbmp = [System.Drawing.Bitmap][System.Drawing.Image]::FromStream($iconstream)
$iconhandle = $iconbmp.GetHicon()
$icon = [System.Drawing.Icon]::FromHandle($iconhandle)

#LAPS UI FORM
$lapsform = New-Object system.windows.forms.form    
$lapsform.Size = New-Object System.Drawing.Size(400,320)
$lapsform.Text = "                                     LAPS UI         "
$lapsform.StartPosition = "centerscreen"
$lapsform.FormBorderStyle = "fixed3d"
$lapsform.Icon = $icon

#LAPS TEXTBOX LABEL
$lapsform_computername_textbox_label = New-Object System.Windows.Forms.Label
$lapsform_computername_textbox_label.Location = New-Object System.Drawing.Point(20,20)
$lapsform_computername_textbox_label.Size = New-Object System.Drawing.Size(100,15)
$lapsform_computername_textbox_label.Text = "ComputerName"
$lapsform.Controls.Add($lapsform_computername_textbox_label)

#LAPS TEXTBOX
$lapsform_computername_textbox = New-Object System.Windows.Forms.TextBox
$lapsform_computername_textbox.Location = New-Object System.Drawing.Point(21,40)
$lapsform_computername_textbox.Size = New-Object System.Drawing.Size(250,15)
$lapsform.Controls.Add($lapsform_computername_textbox)

#VARIABLE FOR KEYDOWN
$lapsform_computername_textbox_keydown = {}

#KEYDOWN ASSIGNED
$lapsform_computername_textbox_keydown = [System.Windows.Forms.KeyEventHandler]{
    if ($_.keycode -eq 'Enter'){
        $lapsform_search_button.PerformClick()
    }
}

#REGISTER KEYDOWN HANDLER TO COMPUTER TEXTBOX
$lapsform_computername_textbox.add_keydown($lapsform_computername_textbox_keydown)

#LAPS SEARCH BUTTON
$lapsform_search_button = New-Object System.Windows.Forms.Button
$lapsform_search_button.Location = New-Object System.Drawing.Point(290,40)
$lapsform_search_button.Size = New-Object System.Drawing.Size(60,20)
$lapsform_search_button.Text = "Search"
$lapsform.Controls.Add($lapsform_search_button)

#LAPS SEARCH BUTTON LOGIC
$lapsform_search_button.add_click({
    if ($lapsform_computername_textbox.Text.Length -le 0){
        $lapsform_output_label.Text = "You must enter a computer name"
    }else{
        try{
            #getting text from textbox
            $computernametext = $lapsform_computername_textbox.Text

            #checking if computer is in AD
            $checkad = Get-ADComputer -Identity $computernametext
        
            #invoking admpwdpassword command on $domaincontroller
            $invokegetadmpwd = Invoke-Command -ComputerName $domaincontroller -ScriptBlock {get-admpwdpassword -ComputerName $args[0] } -ArgumentList $computernametext | Select-Object Password, expirationtimestamp
        
            #getting password and password expiration date
            $lapsform_password_textbox.Text = $invokegetadmpwd | Select-Object -ExpandProperty password
            $lapsform_password_expires_textbox.Text = $invokegetadmpwd | Select-Object -ExpandProperty expirationtimestamp

            $lapsform_output_label.text = ""
        }catch{

            if (!$checkad){
                $lapsform_output_label.Text = "Computer not found"
            }
            #clears password and expiry textbox
            $lapsform_password_textbox.Text = ""
            $lapsform_password_expires_textbox.Text = ""
        }
    }
})

#PASSWORD TEXTBOX LABEL
$lapsform_password_textbox_label = New-Object System.Windows.Forms.Label
$lapsform_password_textbox_label.Location = New-Object System.Drawing.Point(20, 90)
$lapsform_password_textbox_label.Size = New-Object System.Drawing.Size(100,20)
$lapsform_password_textbox_label.Text = "Password"
$lapsform.Controls.Add($lapsform_password_textbox_label)

#PASSWORD TEXTBOX
$lapsform_password_textbox = New-Object System.Windows.Forms.TextBox
$lapsform_password_textbox.Location = New-Object System.Drawing.Point(21,110)
$lapsform_password_textbox.Size = New-Object System.Drawing.Size(250,15)
$lapsform_password_textbox.ReadOnly = $true
$lapsform_password_textbox.Font = New-Object System.Drawing.Font("courier",12,[System.Drawing.FontStyle]::Regular)
$lapsform.Controls.Add($lapsform_password_textbox)

#PASSWORD EXPIRES TEXTBOX LABEL
$lapsform_password_expires_textbox_label = New-Object System.Windows.Forms.Label
$lapsform_password_expires_textbox_label.Location = New-Object System.Drawing.Point(20,145)
$lapsform_password_expires_textbox_label.Size = New-Object System.Drawing.Size(100,20)
$lapsform_password_expires_textbox_label.Text = "Password Expires"
$lapsform.Controls.Add($lapsform_password_expires_textbox_label)

#PASSWORD EXPIRES TEXTBOX
$lapsform_password_expires_textbox = New-Object System.Windows.Forms.TextBox
$lapsform_password_expires_textbox.Location = New-Object System.Drawing.Point(21,165)
$lapsform_password_expires_textbox.Size = New-Object System.Drawing.Size(250,15)
$lapsform_password_expires_textbox.ReadOnly = $true
$lapsform.Controls.Add($lapsform_password_expires_textbox)

#DATETIME PICKER LABEL
$lapsform_datetime_picker_label = New-Object System.Windows.Forms.Label
$lapsform_datetime_picker_label.Location = New-Object System.Drawing.Point(20,200)
$lapsform_datetime_picker_label.Size = New-Object System.Drawing.Size(150,20)
$lapsform_datetime_picker_label.Text = "New Expiration Time"
$lapsform.Controls.Add($lapsform_datetime_picker_label)

#DATETIME PICKER
$lapsform_datetime_picker = New-Object System.Windows.Forms.DateTimePicker
$lapsform_datetime_picker.Location = New-Object System.Drawing.Point(21,220)
$lapsform_datetime_picker.Size = New-Object System.Drawing.Size(250,15)
$lapsform_datetime_picker.Format = "custom"
$lapsform_datetime_picker.CustomFormat = "dd MMMM yyyy"
$lapsform.Controls.Add($lapsform_datetime_picker)

#DATETIME PICKER SET BUTTON
$lapsform_datetime_set_button = New-Object System.Windows.Forms.Button
$lapsform_datetime_set_button.Location = New-Object System.Drawing.Point(285,220)
$lapsform_datetime_set_button.Size = New-Object System.Drawing.Size(91,20)
$lapsform_datetime_set_button.Text = "Set and Update"
$lapsform.Controls.Add($lapsform_datetime_set_button)

$lapsform_datetime_set_button.add_click({

    if ($lapsform_computername_textbox.Text.Length -le 0){
        $lapsform_output_label.Text = "You must enter a computer name"
    }else{
        try{    
            $datetimepickervalue = $lapsform_datetime_picker.value.ToString("MM dd yyyy")
            #getting text from textbox
            $computernametext = $lapsform_computername_textbox.Text
    
            #checking if computer is in AD
            $checkad = Get-ADComputer -Identity $computernametext
            
            #invoking admpwdpassword command on $domaincontroller
            Invoke-Command -ComputerName $domaincontroller -ScriptBlock {reset-admpwdpassword -ComputerName $args[0] -wheneffective $args[1] } -ArgumentList $computernametext, $datetimepickervalue 

            #setting value of output label
            $lapsform_output_label.Text = "Password reset request was successful - GP updating - PLEASE WAIT"

            Invoke-GPUpdate -Computer $computernametext -ErrorAction SilentlyContinue

            $lapsform_output_label.Text = "Finished"
        }catch{
            #checking if computer is in AD
            if (!$checkad){
                $lapsform_output_label.Text = "Computer not found"
            }else{
                write-host "Another issue - WinRM probably isn't allowed..."
            }
    
        }

    }
})

#OUTPUT TEXTBOX
$lapsform_output_label = New-Object System.Windows.Forms.Label
$lapsform_output_label.Location = New-Object System.Drawing.Point(1,265)
$lapsform_output_label.Size = New-Object System.Drawing.Size(385,20)
$lapsform_output_label.BackColor = "white"
$lapsform_output_label.BorderStyle = "fixedsingle"
$lapsform.Controls.Add($lapsform_output_label)

#LAPS UI FORM DIALOG
[void]$lapsform.ShowDialog()

Submitting a CSR for Signing by a CA

Bit of a weird post today, I had a need to update the SSL certificate for an old DRAC (Dell Remote Access Controller) 5 module. This is just an overview of what I did.

First I logged into the DRAC and went to System > Remote Access > Configuration > SSL > Generate a new certificate signing request (CSR). In here I entered my details and put the address I would use for connecting to the server as the common name.

After I clicked “Submit”, I got a small txt file called “csr.txt”. I then needed to get this signed by a Certificate Authority (CA) so that I could get an actual certificate file. Note that the format you want for DRAC 5 is .cer

The CA I used for this was “getacert“, they’re a bit “ghetto” with their site not even using the technology that they provide… kind of ironic but I was desperate.

On this site I entered the contents of my csr.txt file and clicked “Submit CSR“. This them gave me the certificate file, signed by getacert.

Finally, I went back into the DRAC management webpage (in the same location as pointed out earlier) and selected the option to “Upload Server Certificate” Now just select the .cer file you got from the CA and click submit. This will cause the management site to go down for a couple of minutes whilst it configures the new certificate.

After this you should be all set. Enjoy!

Desktop Icons Disappeared

This is a weird issue I encountered where even though I had tried restarting explore.exe and disabled and enabled desktop icons, they still weren’t showing. Even weirder was the fact that only some of them were showing whilst others weren’t. Weird indeed.

Here you can see that the text file “Test” isn’t showing on my desktop even though it is in the desktop folder:

Desktop Icons

 

 

 

Desktop Folder #1

 

 

 

 

 

To remedy this issue, what I had to do was right click on the desktop, go into “Sort By” and select “Name“. This jiggled the desktop and made the text file appear. Not sure what causes this at all.

Hopefully someone finds this useful, I know I could have done with this information at the time. Enjoy!

Unix Permissions Winform

In this post, I will show case a winform application that I have just finished building which will tell you the correct command when given the required permissions. For example, a read permission is identified as a 4 in Unix environments.

I have created a small table below:

 Permission Level  Permission Bit
 Read  4
 Write  2
 Execute  1

Since you need to define permissions for: the owner; owner group and others, you need to supply 3 permission bits per command. Plus one more for special permissions at the beginning but we can ignore that for now.

So if we wanted to give the below permissions:

Special – ignore

Owner – read (4), write(2) and execute(1)

Owner group – read(4) and write(2)

Other – read(4)

we would use the following command: chmod 0764 <path-to-file>

Now we can get on with the actual winform… I created this to tell me what permissions I needed to assigned. Below is a screenshot of the winform:

Front Winform

This also keeps a short history of the permissions in the history textbox which is flushed after so long to stop the textbox from overflowing. Here is a download for the project, in the zip folder is both a ps1 file and an exe file. Enjoy!

 

 

 

Coloured BASH Output Using TPUT

From my previous post, found here, you can see that I have formatted the text to be a specific colour depending on what sort of output I get. So for errors I make the text red and for successful messages I make the text green.

This is easy to implement into BASH scripts and a lot of other formatting can be applied as well. In this post, I will be covering the colorization (probably not a word), underlining, bold text and resetting the changes.

Colour Possibilities:

  • 0 – Black
  • 1 – Red
  • 2 – Green
  • 3 – Yellow
  • 4 – Blue
  • 5 – Magenta
  • 6 – Cyan
  • 7 – White
$(tput setaf 1)TEXT HERE

Bold Text:

#Starts bold characters

$(tput bold)TEXT HERE

#Ends bold characters

$(tput sgr0)TEXT HERE

I would just like to add here that tput sgr0 removes all formatting and returns text to the default style and colour.

Underlining:

#Starts underlining

$(tput smul)TEXT HERE

#Ends underlining

$(tput rmul)TEXT HERE

Below is a full script which includes all the possible combinations of the examples above, apart from black text.

#!/bin/bash

echo "
regular bold underline
$(tput setaf 1)Text $(tput bold)Text $(tput sgr0)$(tput setaf 1)$(tput smul)Text$(tput rmul)
$(tput setaf 2)Text $(tput bold)Text $(tput sgr0)$(tput setaf 2)$(tput smul)Text$(tput rmul)
$(tput setaf 3)Text $(tput bold)Text $(tput sgr0)$(tput setaf 3)$(tput smul)Text$(tput rmul)
$(tput setaf 4)Text $(tput bold)Text $(tput sgr0)$(tput setaf 4)$(tput smul)Text$(tput rmul)
$(tput setaf 5)Text $(tput bold)Text $(tput sgr0)$(tput setaf 5)$(tput smul)Text$(tput rmul)
$(tput setaf 6)Text $(tput bold)Text $(tput sgr0)$(tput setaf 6)$(tput smul)Text$(tput rmul)
$(tput setaf 7)Text $(tput bold)Text $(tput sgr0)$(tput setaf 7)$(tput smul)Text$(tput rmul)
"

I know it looks quite horrible in the source code but this is what the output looks like:

Full possibilities

Enjoy!

Linux Service Restart Script

I required a way to easily restart some common services on my Raspberry Pi running Plex since I kept forgetting whether I needed to use the:

service NAME restart

syntax, or the:

systemctl restart NAME

syntax for the services.

So I created a bash (.SH) file that would allow me to chose which service to restart without having to remember the different commands. Below are my requirements:

  • Give a list of services
  • read which service to restart
  • Restart service
  • restart script

You can see my script below:

#!/bin/bash

restart_script () {
 bash /home/pi/restartservices
}


NUMBER=1
echo "$(tput setaf 3)Following services available:"
echo ""

#LIST SERVICES

for SERVICE in "VSFTPD" "Plex" "VNC Server" "LightDM"
 do
 echo "$(tput setaf 3)($NUMBER)$(tput setaf 7)$SERVICE"
 NUMBER=$[$NUMBER +1]
done

echo ""
echo "$(tput setaf 3)(E)xit:"

read -p "$(tput setaf 3)Chose a service to restart:" READINPUT

if [ $READINPUT = "1" ]
 then
 echo "$(tput setaf 3)Restarting VSFTPD Service...."
 sudo service vsftpd restart
 echo "$(tput setaf 2)Success!"
 restart_script
elif [ $READINPUT = "2" ]
 then
 echo "$(tput setaf 3)Restarting Plex Service...."
 sudo service plexmediaserver restart
 echo "$(tput setaf 2)Success!"
 restart_script
elif [ $READINPUT = "3" ]
 then
 echo "$(tput setaf 3)Restarting VNC Server...."
 sudo service vncserver restart
 echo "$(tput setaf 2)Success!"
 restart_script
elif [ $READINPUT = "4" ]
 then
 echo "$(tput setaf 3)Restarting LightDM Service...."
 sudo systemctl restart lightdm
 echo "$(tput setaf 2)Success!"
 restart_script
elif [ $READINPUT = "E" ] || [ $READINPUT = "e" ]
 then
 echo "$(tput setaf 3)Exiting Script"
 exit 1
else
 echo "$(tput setaf 1)INVALID RESPONSE - WILL LOOP UNTIL RESPONSE IS VALID!"
 restart_script
fi

Rather than having to type in the name of the service I wanted to restart, I used a for loop to add a number to each entry in the services list. This can be found from line 14 to line 19.

Then to run my script from a terminal session, I simply type “./restartservices”

Enjoy!

Server Reboot Script

Running a little low on content this last few months, plus I’ve been busy with other work stuff.

I had the requirement to create a PowerShell script that would get the uptime of a server and then decide whether or not the server needed rebooting.

I also wanted the script to randomize the reboot of the servers, that way if there are multiple servers that need rebooting at once, they don’t cause a power spike or resource issues on the hosts. I did this by creating a random number between 1 and 5 and then if the number equals 5, the server is rebooted. If not then the server isn’t rebooted.

This is the script that I ended up with and what is currently being tested:

$loglocation = "C:\scripts\reboot\log"
$dateforfile = Get-Date

#GETS UPTIME IN DAYS
$lastbootuptime = Get-WmiObject win32_operatingsystem
$uptime = (Get-Date) - ($lastbootuptime.converttodatetime($lastbootuptime.lastbootuptime))
$uptimeindays = $uptime.days

#GETS RANDOM NUMBER
$randomnumber = Get-Random -Minimum 1 -Maximum 6

if ($uptimeindays -ge "14"){

 Add-Content -Path "$loglocation\$env:COMPUTERNAME.txt" -Value @"
=====================================================================================
Server restarted at:
$dateforfile
This was an immediate shutdown as the server had been up for $uptimeindays days
"@

 Restart-Computer -Force

}elseif ($uptimeindays -lt "14" -and $uptimeindays -ge "7"){

    if ($randomnumber -eq "5"){

        Add-Content -Path "$loglocation\$env:COMPUTERNAME.txt" -Value @"
=====================================================================================
Server restarted at :
$dateforfile
This was a random restart as uptime was only $uptimeindays days
"@
        Restart-Computer -Force
    }else{

        Add-Content -Path "$loglocation\$env:COMPUTERNAME.txt" -Value @"
=====================================================================================
Server NOT restarted
$dateforfile
This was not randomly restarted. Uptime is currently $uptimeindays days. Random number was $randomnumber
"@
    }
}else{

Add-Content -Path "loglocation\$env:COMPUTERNAME.txt" -Value @"
=====================================================================================
No restart required
$dateforfile
No restart required since uptime is only $uptimeindays days
"@
}

The first time I created this script and set it up as a scheduled task, nothing happened. Turns out that I needed the -Force parameter in order for the server to be rebooted.

This will later be used in a group policy without the log creating as that is only necessary in the testing stage.

Enjoy!

 

Creating a Logon Script To Cleanup User Directories

In this post, I’ll discuss how I created a PowerShell script that runs when a user logs out of a terminal server and cleans up a directory in their home folder that was filling up with space due to application crashes.

This is the script I created:

$username = $ENV:USERPROFILENAME

$testpath = Test-Path -Path "$username\AppData\Local\Microsoft\Windows\ApplicationFolder"

if ($testpath -eq $true){

 $items = Get-ChildItem - Path "$username\AppData\Local\Microsoft\Windows\ApplicationFolder"

 foreach($i in $items){

  Remove-Item -Path "$username\AppData\Local\Microsoft\Windows\ApplicationFolder\$i" -Recurse -Confirm:$FALSE

 }

}else{}

This code will get the users profile root path and then check if the application folder exists, if it doesn’t then the script ends. If it does exist, the script will cycle through each entry and remove it.

The -Confirm:$FALSE parameter was added because the script kept asking for confirmation when deleting each item. This stops this behaviors and deletes each item without a confirmation prompt.

Now that I have the script and it is working as expected, I create a local group policy that will use:

Name – “powershell.exe”

Parameters – “-F “C:\path\to\file.ps1”

You can see this in the screenshot below:

Logoff script group policy

 

This group policy was added under:

User Configuration – Windows Settings – Scripts (Logon/Logoff) – Logoff

Hopefully you can replicate what I have done and don’t experience any issue. Note that you might need to change the script execution policy on the machine before this works properly. Just something to keep in mind if the group policy isn’t working. Enjoy!

SharePoint URL Changing

There are two main ways that I change the URL of a list or library on a SharePoint site. First off I’d like to explain why I often have to do these tricks. Whenever you create a new SharePoint site from a template, even after you change the names of all the lists and libraries in a web page, the URL will still reference what ever the template lists were called.

Option 1 – SharePoint Designer

To change the URL in SharePoint designer, open your site using the URL “http://HOSTNAME/sites/SITENAME” and this should give you list of items in the left hand column resembling the screenshot below:

SharePoint Designer Column

You should see that the bottom option says “All Files“, double click this and go into “Lists“. This will show all of the lists on your site and you should see that they are all using the old name which is the cause of the incorrect URLs. Simply rename these lists to what ever you need and the URL will change.

 

Option 2 – File Explorer

If you don’t see the “All Files” section in SharePoint designer then this method can be used instead. Open a file explorer and navigate to your site. You can see how I have done this below:

File Explorer

Now go into “Lists” and you should be able to see the incorrectly named lists. Simply rename these lists and the URL will change.

 

I’m not sure why the “All Files” section in SharePoint designer doesn’t show so If anyone can shed some light on that I would be appreciated. Enjoy!

Converting IP to Binary and Back!

This week on “I learn a weird, semi-useless skill” brings you how I learn to convert 32 bit IP addresses into their binary counter part and back. If I asked you if you have ever or would ever need this knowledge, you’d probably say no. But the learning must continue!

Firstly, lets pick an IP address, this can be any random combination of 4 pairs of 3 digits between 0 and 255. For this guide, I’ll be using 176.42.6.213. For no apparent reason.

So to convert this number into binary, I use a simple table method. You can see the table below:

128 64 32 16 8 4 2 1

This table makes it very simple to work out how to convert each of the four octets in an IP address to binary.

First we start with 176

We go through each of the numbers in the table above and see if the column number can be subtracted from the first octet of the 32-bit address. So our first step would be, can we subtract 128 from 176?

The answer is YES so I would put a “1” in the 128 column, and our remainder from the above sum is “48“. Your table should look similar to the one below.

128 64 32 16 8 4 2 1
 1

Now we can do the next step using our remainder of “48“. Can we subtract 64 from 48?

The answer is NO so I would put a “0” in the 64 column. When the answer is no, then the remainder stays the same, so the next sum would be, can we subtract 32 from 48? This goes on until you are at the end of the table and your remainder should be 0.

The finished table for the 176 part is shown below:

128 64 32 16 8 4 2 1
1  0  1  1  0  0  0  0

Once you have done this for all 4 octets in the IP address, you should end up with 4 tables filled with 1’s and 0’s. The full binary number for our IP address is:

10110000.00101010.00000110.11010101

Converting Binary to the 32-bit IP address is quite a lot simpler. Once again we use the same table but this time we put the binary number into the table and read which numbers have a 1 and which numbers have a 0 in the column.

For example, plugging the binary of “176” into the table gives us the below result:

128 64 32 16 8 4 2 1
1 0 1 1 0 0 0 0

From this we can see that the following columns have a 1 assigned to them:

  • 128
  • 32
  • 16

Now all we have to do is add these numbers together to get the first octet of the 32-bit address, which is “176“. Now do this process for the other 3 parts of the binary address and you will get back the original IP address of “176.42.6.213

I would suggest doing this exercise multiple times to really nail it if you need to. Who knows, if you and your company are really sad and nerdy, this might be a nice party trick. Or a particularly cringey 15 minutes.

I think I explained this well enough. If not, please comment and let me know what parts I could improve or add. Enjoy!

P.S You have also want to use this form I created to do this activity: Converting 32-Bit Address to Binary and Back