Calculate a file hash without 3rd party tools on Windows & Linux.

Calculate a file hash without 3rd party tools on Windows & Linux.

If you need to generate a hash of a file (e.g. MD5, SHA256 etc) then there are numerous 3rd party tools that you can download but if you are restricted to only built in tools or don’t need to do this often enough to install something then there are built in OS tools for Windows and Linux that can be used.

Windows:

For Windows there is “certUtil” which can be used from the command prompt console with  the “-hashfile” option to generate a hash for a supplied file:

CertUtil [Options] -hashfile filePath [HashAlgorithm]

The [HashAlgorithm] options are MD2, MD4, MD5, SHA1 (default), SHA256, SHA384 and SHA512.

For example to get an MD5 hash of a file use:

CertUtil -hashfile C:\ExampleFile1.txt MD5

More documentation for CertUtil can be seen here.

For those with access to PowerShell v4  and above (Windows 8.1 & Win Server 2012 R2) you can use the built in commandlet called get-filehash like this:

Get-FileHash C:\ExampleFile1.txt  -Algorithm MD5 | Format-List

The algorithms supported are SHA1, SHA256 (default), SHA384, SHA512, MACTripleDES, MD5 & RIPEMD160.

For Powershell versions prior to V4 there are numerous scripts available on the web that will work out the hash for you using various methods.

Linux:

For Linux use the correct  hashalgorithmSUM command in the terminal for the algorithm you are looking for, i.e. for an MD5 hash use md5sum or for SHA512 hash use sha512sum.

For example:

md5sum /home/rich/Documents/ExampleFile1.txt 
sha1sum /home/rich/Documents/ExampleFile1.txt
sha512sum /home/rich/Documents/ExampleFile1.txt

 

 

Advertisements

Using a Sure Electronics LCD with the Raspberry Pi using Python

Using a Sure Electronics LCD with the Raspberry Pi using Python

After receiving a new Raspberry Pi 3 at Christmas I quickly set off looking for uses for this wonderful machine, and quickly found myself hooking it up to an LCD display. This post covers the Python driver I used and modified, as well as some other useful resources.

RPi3

Firstly as an owner of the original Raspberry Pi model B I was pleasantly surprised how capable the Raspberry Pi version 3 is. The performance is much improved and the new built in wireless is a superb addition which makes this version of the Pi more  usable and reduces the friction caused by having too many USB devices hanging off it like a mutant spider. The Pi v3 is powerful enough to be used as a basic workstation and I found myself working on it directly (within Raspbian OS) making the coding workflow more enjoyable as a result than the previous models. Also the as VNC Server is now built into the Raspbian OS it makes setting up the Pi as headless very easy. In fact once you have installed Raspbian and setup VNC then you can run it with just the power supply connected which makes it use little space and you can locate it anywhere.

SureElecLCD1Once my Pi3 was up and running I decided to connect an old LCD matrix screen to it. This LCD is Sure Electronics 20×4 screen which I bought years ago to attach to my HomeServer but never got around to it. The LCD has a USB interface and was used on Windows via the LCD Smartie application. A quick google showed that LCDProc is an equivalent tool for using LCD screens with Linux, and I found some useful tutorials (e.g. here & here). You can install LCDProc via “apt-get install lcdproc”.

I only had limited success with LCDProc but soon realised what I really needed was a programmatic way of controlling the LCD as opposed to a general display tool, so after some more googling I found a few variations of python drivers were being used to control similar LCDs, and this “Smartie” driver by Steve Davis worked best for me, which in turn was inspired by this driver. These drivers use the “pyserial” Python module, easily installable via Python PIP package manager:

“apt-get install python-pip” or “apt-get install python3-pip” (for python v3 pip)
followed by “pip install pyserial==3.0”.

RaspberryPiWhilst the smartie driver initially worked I found that it failed to work after a reboot. After some serious head scratching I realised that it would always work after running LCDProc, meaning the initalisation code for LCDProc setup up the LCD successfully for the Python driver to communicate.  After digging into the Sure Electronics manual and digging into the source code for the SureElec driver for LCDProc (here & here) I was able to find the initisiation command codes for the LCD and add this to the smartie python driver. This enabled the Python driver to be used without relying at all on LCDproc or similar software.

 I have also added some new functionality to the driver which includes flashing, wrapping text and scrolling multiple lines etc. Also included is a demo function that runs through the various functions provided by the driver to show what’s possible and to help testing after making any modications. My updated driver can be found on my GitHub repo (https://github.com/RichHewlett/smartie). With this driver i was able to control my LCD backlight, display text and get a temperature reading. The fact that it was writen in Python was a bonus as I find Python a great langage for coding fun projects.

SureElecLCD2

If you have a Sure Electronics LCD you may be able to take this and use it, or modify it as required, although there are many variations of these devices. Once you have connected your LCD and rebooted the machine just check that the LCD is on the right USB port in Linux (e.g. /dev/ttyUSB0) and that the user has permissions on that port. If you have a Sure 16×4 screen then this will probably work by modifying the SCREEN_WIDTH constant to 16. If you have a different LCD Screen then you may need to modify the initalisation codes and command strings that get sent to the LCD by each method. A good source of refercence is to check out the LCDProc source code for their bundled drivers as they support many screens.

In the next post I’ll cover my next step of building Python Web App using Flask to control the LCD screen from a browser.

Using Ubuntu via VirtualBox Seamless Mode

Using Ubuntu via VirtualBox Seamless Mode

I like Ubuntu and I enjoy using it, although I’m still a windows guy at heart (at least for the time being anyhow but we’ll see if Win8 ever grows on me) and I use a lot of Windows only apps. The approach I’ve been using for the last few months with great success is VirtualBox’s Seamless mode.

SeamlessModeImage

I run Ubuntu in a VirtualBox guest VM on top of a Windows 8 host (although it could be the other way around) and when its running I run it in Seamless Mode. My virtual Linux PC is then running in a normal desktop window and my mouse and keyboard works seamlessly between them.

SeamlessDesktop

I effectively have two desktops here, my Windows one and my Ubuntu one. If you set up a shared folder between the two machines within VirtualBox its easy to share files too. Of course you don’t get the performance benefit of running Linux directly on the hardware as you would with a dual boot configuration but dual booting doesn’t provide the ability to interact between the OS’s.

This approach is the best way I’ve found yet to run Linux and Windows together.

You can also go further for some OS configurations and use Seamless Windows if your setup allows, which enables your guest OS windows to be displayed side by side with the host OS’s windows.

Hello Linux – Again

Hello Linux – Again

I’ve been increasingly interested in the Linux OS again recently and have re-discovered it’s power and flexibility. I’m a Windows guy primarily, always have been, but I’m writing this on the new Ubuntu 11.04 (Natty Narwhal) release and I must say I am enjoying the experience.image

This is by no means my first foray into the world of Linux, in fact my first exposure was way back 1999 (wow was it that long ago?) when I heard about this magical version of Unix  that ran on PC hardware. At that point my home PC was running Windows NT on a Pentium 166 with a heady 64MB Ram. I purchased a Linux book that came with a Linux distribution on CD (downloading was not really an option for me back then with a slow dial-up connection). It was Caldera OpenLinux 2.2 and installing it was a nerve racking and sadly enjoyable journey of re-sizing partitions, configuring drivers and general frustration. Eventually I had a dual boot NT and Linux PC and a sense of self satisfaction, but Linux didn’t capture my imagination much further at that point. Much like playing with Lego as a child (or an adult Smile) the fun is in the building and configuring it how you want but not the playing with it afterwards, my fun with Linux was over. The UI felt like a poor relative to Windows and I booted into it less and less. As I moved further into Windows development there was less of a desire for me to explore Linux more. Over the last 12 years I have played with a few distributions on and off but never really for any reason other than curiosity and none of them really stuck. Lately though I’ve started to get the Linux itch again so I got downloading and I’m very pleased with what I’ve found.

Firstly it is now so incredibly quick and easy to get Linux distributions installed and setup on your machine of choice. There are so many options to get you up and running, and with most drivers automatically detected you should get few issues. Of course Virtualisation has made it easy to try out various OSs and Linux is no different. VirtualBox is a joy to use if you want to try out a Linux installation, but there is also the LiveCD option that enables you to run your Linux distribution of choice off a USB or DVD drive without touching your hard drive. Whilst this is not very practical for everyday use its good for getting a real feel for what a Linux distribution is like and what it will be like on your hardware. The best option for me with it’s ease and practicality is Wubi whereby you can install Ubuntu within your Windows OS and it creates a virtual disk on your Windows drive for installation. This means all your files are sitting isolated in a Linux virtual disk file within Windows. You boot into Linux normally (via the Windows dual boot loader screen) and it is completely transparent to your Linux OS that it’s disk is actually virtual. Of course there is a performance overhead around disk access but its not noticeable even on my netbook. This approach allows you to get all the benefits of a Linux installation without having to go full hog straight away with partitioning your disk. I’ve been running Ubuntu for a while using this approach and its working a charm. I do intend to go the full hog soon and install a fresh install of Ubuntu onto its own partition when I get around to it but as it works so well I’m in no rush. In the meantime I can try out some other Linux distro’s to find the one for me (Linux Mint and Tiny Core are on my list to checkout).

Ubuntu Unity DesktopUbuntu is certainly a relatively user friendly Linux distribution and whilst the switch to the new Unity desktop for  the latest 11.04 version is very controversial within the Linux community there is little doubting that it is a friendly experience to new Linux users. It is also a very good desktop experienced for Netbooks, which is probably why it’s working so well for me on my netbook. I’m not sure how it will scale up to my desktop yet and do understand the negative comments that have been pitched at it. Regardless it is a way of Ubuntu differentiating itself from Windows and Mac, whilst making itself as user friendly as possible. It does appear as though Unity is a first step towards Ubuntu becoming a touch friendly device like Linux distribution. I’ve commented before on this blog how i see devices replacing the PC for all but “power user” type consumers and yet I still feel that a light friendly Ubuntu (with the power still underneath for those that want it) can do well. My wife is happy using Ubuntu on my netbook because like many consumers she does almost everything in the browser and this is where Linux on a Netbook seems to shine, as its capable, light and fast. A key advantage for Ubuntu is the Ubuntu Software Centre which is ideal for new users to get up to speed quickly. Overall I have been pleased with how Ubuntu plays with my Windows network shares and was pleased that I haven’t even needed to install a Remote Desktop client to logon onto my Windows servers as there is one included (type rdesktop servername at the terminal).

It’s still early days with my latest affair with Linux but so far it’s going well and this time I might get totally hooked.