Category Archives: General

General stuff, usually just stuff related to networking and admin.

Using Azure DNS for dynamic DNS

As a long time user of DynDNS and a generally happy customer, I’ve paid for their dynamic DNS services to provide my regularly changing home IP address to keep my website up and running using a combination of a rather badly named DynDNS domain zone with CNAME records for my actual domain resolving the DynDNS zone.

I’ve avoided taking up their rather expensive Managed DNS services at $7 per month to provide a very simple service but a recent job I’ve been working on has had me looking at all of Microsoft’s Azure services in detail. Despite it being in preview, I decided to take a closer look at Microsoft’s Azure DNS to see what it can do.

In essence, Microsoft Azure DNS allows you to host your domain zone and records in Azure but not to purchase a domain. For example, to use Azure DNS you must use a domain registrar to purchase a domain (or have one already) and then delegate the zone to Azure DNS by altering nameservers of the zone to Microsoft’s. This is usually very straightforward to do but differs between registrars. My domain registrar is 123-reg so their nameserver update page looks as follows. Ignore the nameserver settings here, yours are likely different.

123-reg-nameservers

I’m not going to go through the process of signing up for Azure etc. There’s plenty of documentation out there covering the process in graphic detail.

As you know from the title of this post, the reason for doing this is to implement a dynamic DNS solution for your own domain using Azure DNS. Typically, for static IP addresses this is completely unnecessary but in my circumstances, where I host my personal website from my own home network and have a frequently changing IP address, it’s a necessity. Compared to DynDNS’ managed DNS services at $7 per month for their lowest bracket ($84 per year!), Azure DNS is an absolute STEAL, charging only 15 pence per zone, per month for the first 25 zones. This pricing represents a 50% discount over production prices while the service is in preview but even then, if I had 5 zones hosted in Azure, I’d spend less than 25% on DNS costs compared to DynDNS.

Just to re-iterate,  Azure DNS is in preview for now. For my purposes (personal use for my own blog) it’s fine. If people can’t reach my site for a short while, it isn’t the end of the world – that said, I don’t expect that to happen.

So, back to it. We’ve got a domain and we have delegated it to Azure DNS by changing the nameservers at our registrar’s site. So how do we use this for Dynamic DNS? Azure DNS exposes three methods of configuration, unfortunately a REST API isn’t one of them but PowerShell is. A short while ago I created a PowerShell script that could be used to update DynDNS records using pure PowerShell so this can be used as a template for integrating with Azure DNS. The trade-off is the need to run a PowerShell script from inside your network. I’ve no doubt there’s a way to integrate this with Azure Automation with Webhooks and it may be a little extension project I use to expand on this article in the future but for now, this is a script that must execute from inside the network with the IP address you will use to update Azure DNS records.

The process itself is very simple; get the current IP address of your Internet connection, compare it with what’s set for the A record in the Azure DNS zone and if it doesn’t match, update the record in the zone. Easy really.

Here’s a script that’ll get that done.

Initially it starts out by obtaining the Internet connection’s IP address from the router, you could just as easily do this by obtaining the IP from something like my own tool. https://showextip.azurewebsites.net/ – as it is, asking my own DD-WRT router is less expensive.

I then compare the current IP address with the value currently set on the record I’m interested in – in this case lewisroberts.com  – just the apex/root record, not www .

If it isn’t the same, I bounce on to Azure DNS and forcefully update the record and enforce a 60 second TTL.

Using this method I can avoid paying for DynDNS services at all and rather than using CNAMEs for my domain names, I can use actual IP addresses.

– Lewis

Hive Active Heating PowerShell Control with PoSHive

Last week I announced PoSHue, my PowerShell 5 class for controlling and scripting Philips Hue lights – this week sees another announcement along the same lines.

I recently bought a Hive Active Heating system to remotely control my home’s heating and thought it would be pretty cool to be able to access that same level of control (and automation) using PowerShell.

PoSHive-icon

PoSHive is the result. It’s another GitHub project meaning anyone can get a copy, fork it, branch and contribute.

UPDATE: It’s now also available from the PowerShell Gallery.

powershellgallery

Install by simply using:

install-poshive

When you want to ensure you have the latest version:

Why would I want access to Hive using PowerShell? The purpose of this class is to enable you to use PowerShell (v5) scripting to exert more powerful logic control over the state of your heating system. In its basic form, it allows you to set the heating mode of the system and the temperature, including the Boost option, Holiday mode and even to advance the system to the next event. PoSHive offers most (if not all) the features exposed by the app and website but using only PowerShell.

I realised a different benefit for PoSHive as I was thinking about use cases and realised that it opens the Hive Ecosystem (heating only) to those with disabilities that means it’s hard or even impossible to use an app on a phone or the website simply due to impaired sight or the fine motor control that you may need to use a mouse or point with a finger. The app offers disabled users the chance to simply type commands and have the heating system respond to them. No fiddly apps or websites to contend with.

Here’s a basic example showing how to get the current temperature recorded by the thermostat. The first 4 lines of this script can even be included in your PowerShell profile so all you need to type is $Hive.Login()  and you’re logged on.

poshivebasics130

 

Please check out the project on GitHub and contribute if you can or just let me know how you use PoSHive in your script through the comments section below.

The project is not sanctioned by or affiliated with British Gas in any way and is based on API data formats and responses I’ve observed for my own Hive Active Heating system. The class is designed to work only with the Heating only Hive system (I don’t have the hot water system unfortunately) and is likely also not to work with Multi-zone Hive systems.

-Lewis

Philips Hue PowerShell

I’ve been quietly working on a little project (or two) of my own on GitHub since I got some Philips Hue lights a while back.

Philips makes accessing the bulbs programmatically very easy with the API that exists on the Bridge device but I wanted a scriptable solution to allow me to exert much more fine grained logic control over the states and colours of my lights.

Being pretty advanced with PowerShell (at least, I think I am), I set about writing a PowerShell interface (not a GUI) to allow me to access the properties and set the state of my Hue lights.

The result is a PowerShell 5 class that simplifies the interaction with Philips Hue bulbs and lights that I’ve dropped on to GitHub for use by any and all. I realise this is focussed purely on Windows users but that’s what I am and I use PowerShell extensively for other things too.

The project is called PoSHue and is located on GitHub.

It allows you to do things like this from PowerShell.

Feel free to have a look and see how you can use it. Just 4 lines and you’re off and running.

HueLight

One example is something I’m using the classes for currently but is logically quite complicated. The script executes on a schedule, that schedule is set from the previous execution and is obtained from an API call to a service providing sunset times. The script turns the lights on just before sunset but only if me and/or my fiancee are home.

I then have a second script which is executed by the “turn lights on if it’s sunset and people are home” script which monitors if we go out. If we go out, the lights are turned off by this script and, so long as it’s before 23:00, the turn lights on only if we’re home script is executed again to wait for us to come home again.

Basically, the scripts work in conjunction and cyclically to ensure the lights don’t turn on before sunset and only when we’re home and they also turn the lights off if we go out but would turn them on again if we came home before 23:00.

Let me know if you’d be interested in seeing the scripts and tasks (yes they’re scheduled tasks that monitor for return events from the scripts!) and I’ll see what I can do about packaging them up somewhere.

-Lewis

 

 

Investigatory Powers Bill #IPBill

I celebrate by 500th post on my blog with a letter to my MP to decry the actions of Government and its intention to force the #IPBill through Parliament. I would urge anyone that cares about their privacy (not just what websites you visit!) to write to their MP asking them to challenge the Investigatory Powers Bill when it is debated in Parliament on the 14th March 2016. It has taken the Home Office just six weeks to publish two drafts of the IPBill and set a date for its debate – is that really enough time to properly understand the implications of this bill?

Know this – the most recent draft of the Bill grants the Police (any officer at any time!) to look up your Internet browsing history. Are you friends with a Police officer? Neighbours with one? (I am actually). Do you want them to know what websites you visit?

“Surveillance controls, and absolute surveillance controls absolutely.” — Page 1. Welcome to the Machine: Science, Surveillance, and the Culture of Control

Here is my letter.

Dear ​xxxx,

I write ​again ​to voice my serious concern at the intention to rush the Investigatory Powers Bill through Parliament without proper scrutiny.

The Home Office has been told to examine carefully the criticisms and recommendations of three Parliamentary committees. Less than three weeks since the release of the previous draft of the Investigatory Powers Bill is not enough time for a considered redrafting of the Bill and proves only that the Home Office has paid little attention to the criticisms made of the original Bill. The new Bill only has a few significant changes from the draft version and is a slap in the face for any democratic and free society.

The Bill reinforces the assumption of the security services (and seemingly Government) that everybody is a potential criminal. We are being forcefully relieved of the freedom to conduct our lives without scrutiny by an overbearing, overreaching state. The plan to monitor everybody’s Internet browsing history in order to catch a few criminals and terrorists amounts to bulk surveillance of an entire population and is a significant overreach of state powers – no other country in the world monitors and collects Internet browsing history to this extent and I am horrified that the UK wishes to be the first, under the auspices of increasing safety when no evidence can be provided to confirm this assertion.

The Bill is a huge step in the wrong direction away from democracy. It provides insufficient judicial oversight and assumes that the state and its actors are (and will continue to be) entirely trustworthy when it has been proven time and again that they are anything but. The Government’s purpose is to serve the citizens of this country and I am appalled at the continual battering ram of fear being used by the Government to drive through a piece of legislation that can be described as nothing but draconian.

“The premise [is] that privacy is about hiding a wrong. It’s not. Privacy is an inherent human right, and a requirement for maintaining the human condition with dignity and respect.” — Bruce Schneier, computer security and privacy specialist.

Who I talk to, when I talk to them, where I am, what time I’m awake at night, what websites I visit and when I visit them are all private matters that do not threaten national security and the availability of that information to the security services is useless – the Government is suggesting that only it, the security services and (now) Police should be the judge of that.

It concerns me greatly that the personal opinions of  a small number of individuals in positions of trust and the actions of just a few criminals are set to affect the private lives of tens of millions of innocent, law abiding people.

The social and democratic effects of implementing this digital Panopticon cannot be underestimated and I would urge you to consider the implications of allowing this Bill to pass through without a significant rewrite to properly address the failings highlighted by the three separate Parliamentary committees.

Yours sincerely

Lewis Roberts

PowerShell for DDNS (DynDNS.org)

I’ll just leave this here. I realise many would prefer alternatives to using scheduled tasks such as Windows services or built-in methods from more advanced routers (as I do) but I had a need to write PowerShell to run every hour and update a DynDNS domain if the current IP doesn’t match the DNS IP.

If you’re running this as a scheduled task, you must do it under the context of the same user that creates the credential file.PrtScr capture

Hope it’s useful for you.

-Lewis

Turn off Windows 10 OneDrive link in Explorer Sidebar

Quick couple of lines of PowerShell to turn off the OneDrive integration in Windows Explorer for those of us that use other providers and would like to recover the space taken by the OneDrive link.

Before: After:
onedrivebefore onedriveafter

As a full blown script with a little error checking.

Cheers

Lewis

-Oh, news from this week, I asked my (very dedicated) girlfriend of 7 years to marry me. She said yes. 🙂

Browser Extension Show External IP

Show External IP

I’ve recently written a very small browser extension for both Chrome and Firefox to allow you to see your external IP address with just a single click. No need to open a new tab or ask Google.

Chrome Version

If you’re running Chrome, you can get the extension from the Chrome Web Store. I’ve added a screenshot of the Chrome version below. The intention is that a single click shows you your current external IP address. It works with proxies too so if, like me, you switch between proxies frequently and still need to know your external IP address, this is the tool for you.

Chrome Show External IP Extension

Firefox Version

If you’re running Firefox, you can get that version from the Mozilla Add-on Site (AMO). I’ll admit, Firefox, is, for now, my preferred browser since Chrome keeps inexplicably crashing with no reason or usable information that might allow me to resolve it so the extension was first written for Firefox. I made a couple of changes to the logo/icon between writing the Firefox version and the Chrome version but the Firefox version will get the new icon in due course – I’m just waiting for first approval of the extension in AMO before I submit an update.

showextip (1)

Yes, there are plenty of other extensions out there that do the same thing but the purpose of this exercise was to both learn and give myself an extension that isn’t subject to author changes and the introduction of more “features” (or worse, adverts) that I simply don’t want or need.

I also tend to frequently swap between proxy servers I have running on my network that are attached to VPNs that offer me a number of egress points on the Internet and I’m always curious what my IP address is so a small extension that works in Firefox and Chrome for proxies and direct connections was a good learning opportunity.

There’s nothing mind bendingly difficult in creating the extensions but it’s not bad for knowing nothing about the Mozilla SDK High Level APIs less than 24 hours ago and after I’d done the Firefox extension, doing it in Chrome took just a couple of hours.

If you have feedback or comments, leave them below.

-Lewis

PowerShell Parameters for Modules

One for the personal digital scrapbook. When writing PowerShell modules I always have to dig this up as reference material and I’ve added an example as well.

about_Functions_Advanced_Parameters – https://technet.microsoft.com/en-us/library/hh847743.aspx

Obviously you need to  Export-ModuleMember  when you’ve created the function and save the file as .psm1 to identify it as a PowerShell Module.

After writing my personal use modules, I usually want them to load automatically when I fire up a PowerShell console so I add them to [Environment]::GetFolderPath('mydocuments') + "\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"  usually in a try/catch block.

-Lewis