tag:blogger.com,1999:blog-57636590171591734652024-03-08T20:15:06.610+01:00Roel's IT blogRoHeVehttp://www.blogger.com/profile/02418913823290203666noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5763659017159173465.post-85428210559890349542018-09-15T15:37:00.000+02:002018-09-15T15:37:19.851+02:00Location info based on an IP addressRecently redshift broke due to a change in geoclue2.<br />
<br />
My solution was to go back to the previous working version of geoclue2 (2.4.7-1) and just wait for a fix upstream. It seems that this compatibility issue will not be fixed in redshift or geoclue2 in their packages, so I neew a beter workarround.<br />
<br />
I decided to just enter my location in the startup file, as suggested by several people.<br />
<br />
One of the nice suggestions was to use a simple query to get your ip-based location info in json and extract wat was needed for redshift.<br />
<br />
<pre style="background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; color: #24292e; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 11.9px; line-height: 1.45; overflow-wrap: normal; overflow: auto; padding: 16px; word-break: normal;"><span class="pl-s" style="box-sizing: border-box; color: #032f62;">curl ipinfo.io <span class="pl-k" style="box-sizing: border-box; color: #d73a49;">|</span> jq -j .loc <span class="pl-k" style="box-sizing: border-box; color: #d73a49;">|</span> tr <span class="pl-s" style="box-sizing: border-box;"><span class="pl-pds" style="box-sizing: border-box;">'</span>,<span class="pl-pds" style="box-sizing: border-box;">'</span></span> <span class="pl-s" style="box-sizing: border-box;"><span class="pl-pds" style="box-sizing: border-box;">'</span>:<span class="pl-pds" style="box-sizing: border-box;">'</span></span></span></pre>
<br />
I decided to just put the result of that query into the redshift desktop-file for my pc at home, not the query itself. I noticed that the json returned by <a href="https://ipinfo.io/" rel="nofollow" target="_blank">the ipinfo.io site</a> looked quite nice.<br />
<br />
The location is close enough for use with redshift (well inside a 30 km radius), however it actually suggest another town :-)<br />
<br />
<br />
<br />RoHeVehttp://www.blogger.com/profile/02418913823290203666noreply@blogger.com0tag:blogger.com,1999:blog-5763659017159173465.post-25181302932682423162018-03-18T10:29:00.000+01:002018-03-18T10:30:02.579+01:00Smartmeter P1 in console<div class="tr_bq">
De Nederlandse Smartmeters hebben een P1 poort waarmee je de tellerstand kan ophalen. Een geschikte ' kabel' om op een computer aan te sluiten, kan je zelf maken of kant en klaar kopen..</div>
<br />
Een makkelijke manier is om een P1 naar USR 'kabel' te kopen en die op een raspberry Pi aan te sluiten. Je kan hier zelfs complete domotica setjes voor kopen, waar ook al leuke software op zit, maar je hebt genoeg aan zo'n kabel en een kale RPi.<br />
<br />
Om te testen of het werkt (en zolang je nog geen andere software hebt om wat met de P1 data te doen), zijn de volgende 2 regels (uitvoeren op de commandline) voldoende om te zien wat er uit de meter komt.<br />
<br />
<blockquote>
sudo stty -F /dev/ttyUSB0 115200<br />cat /dev/ttyUSB0 | sed '/^$/d'</blockquote>
<br />
de eerste regel stelt de snelheid in waar de poort mee werkt (115200)<br />
de tweede regel laat alle binnenkomende regels zien (en sloopt de extra lege regels eruit)<br />
<br />
Als je de RPi in de meterkast hebt (en aangesloten op je internet modem/router), kan je overal vanuit je thuisnetwerk inloggen op de RPi en de meterstanden uitlezen. Je kan het natuurlijk zo mooi maken als je zelf wilt, maar dit is het minimum.<br />
<br />
Er zijn voldoende sites op internet met info, ' google is your friend'RoHeVehttp://www.blogger.com/profile/02418913823290203666noreply@blogger.com0tag:blogger.com,1999:blog-5763659017159173465.post-85267073108006628672014-12-23T10:00:00.000+01:002018-03-18T10:50:48.746+01:00Use a MAC address to find a specific network interfaceThis is an old blogpost, unpublished until now, written in 2014 when windows 2008R2 was widely used and windows 2012 was brand new. Who is stil deploying windows 2008 R2 servers? Now you can use the powershell commands on 2012R2 and 2016 to do the same tasks.<br />
<br />
When deploying VMs in an automated way and your VM has more than one network interface and you need to configure static IP addresses, you need to find the interface that corresponds to a specific network. I also assume you want a static IP address for a server and that your server is a Virtual Machine hosted on vCenter or Hyper-V. On that host, you configured the virtual network interface with a specific VLAN and you know the assigned MAC address. Your task is to find the corresponding interface inside the VM and configure it with the right IP configuration.<br />
<br />
The trick is to find the interface with a specific MAC address and then configure it. This should also work on Windows 2008 R2, so the new PowerShell CmdLets in Windows 2012 cannot be used yet.<br />
<br />
WMI to the resque (using Get-WmiObject). Using the <span style="font-family: "courier new" , "courier" , monospace;">Win32_NetworkAdapter</span> class and filtering on AdapterTypeId = 0 gives the list of configured ethernet adapters and the interface index I need.<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: x-small;">$wmiResult= Get-WmiObject -Class Win32_NetworkAdapter -Namespace "root\CIMV2"</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-size: x-small;">$wmiResult | Where AdapterTypeId -eq 0 | select Index,MACAddress | ft -AutoSize</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: xx-small;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">Index MACAddress</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">----- ----------------</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> 10 00:50:50:A0:2D:D1</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> 12 00:50:50:A0:2E:D4</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> 14 00:50:50:A0:2F:D6</span><br />
<br />
The same (and more) data is also available in the <span style="font-family: "courier new" , "courier" , monospace;">Win32_NetworkAdapterConfiguration</span> class, except you cannot filter on 'ethernet adapters' or interface index. On the other hand, if you already know the MAC addresses of the interfaces to configure, then it might still be an option.<br />
<br />
When you know the interfaceindex, you can now configure the interface using netsh (2008R2) or powershell (2012 and up)RoHeVehttp://www.blogger.com/profile/02418913823290203666noreply@blogger.com0tag:blogger.com,1999:blog-5763659017159173465.post-68904188199360167372014-09-06T21:57:00.001+02:002014-09-07T12:25:02.021+02:00Using .NET to convert a WMI datetime to a powershell datetime<span style="font-family: Verdana, sans-serif;">The datetime format for WMI objects (through powershell) is different from the native powershell datetime format, so you need to convert it to PowerShell's native datetime format.</span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">When using 'local' WMI commandlets, this is easy, just call the objects 'ConvertToDatetime' method. But when automating tasks you would collect data using powershell remoting. The powershell object containing the WMI datetime you obtained using remoting, does have all properties available, but not the methods.</span><br />
<span style="font-family: Verdana, sans-serif;">You can create a local WMI object and use it's ConvertToDatetime method, but there is an easier way.</span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">I found that solution by looking for something entirely different in this blog: </span><a href="http://mctexpert.blogspot.nl/2014/06/new-way-to-convert-wmi-time-properties.html"><span style="font-family: Verdana, sans-serif;">New way to convert WMI time properties</span></a>. <br />
<span style="font-family: Verdana, sans-serif;">Simply use </span><span style="font-family: Arial, Helvetica, sans-serif;">[System.Management.ManagementDateTimeconverter]::ToDateTime( ) </span><span style="font-family: Verdana, sans-serif;">with the WMI time as the parameter.</span><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<span style="font-family: Verdana, sans-serif;">This .Net method converts a WMI datetime to PowerShell's native DateTime format. So no need the need to create a local WMI object and then us it's conversion method :) </span><br />
<span style="font-family: Verdana;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">Example code:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Times New Roman;"><span style="font-family: Arial, Helvetica, sans-serif;"></span></span><span style="font-family: Verdana, sans-serif;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: xx-small;">$Computer = 'SERVER01' <br />$wmiResult = Invoke-Command -ComputerName $Computer -ScriptBlock {<br /> Get-WmiObject -Class Win32_OperatingSystem -Namespace "root\CIMV2"<br /> }<br />if ($wmiResult) <br />{<br /> $LastBootTime = [System.Management.ManagementDateTimeconverter]::ToDateTime($wmiResult.LastBootUpTime)<br /> Write-Output "Server $($wmiResult.PScomputerName) with OS version $($wmiResult.Version), last booted on $LastBootTime" <br />}<br />else <br />{<br /> Write-Warning "Server $Computer could not be contacted through WS-Man, please check if the server is up and powershell is enabled"<br />}</span></span><br />
<span style="font-family: Verdana;"></span><br />
<span style="font-family: Verdana, sans-serif;">If you</span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;">are</span><span style="font-family: Verdana, sans-serif;"> only interested in the last boot</span><span style="font-family: Verdana, sans-serif;"> time and not in other properties, y</span><span style="font-family: Verdana, sans-serif;">ou can do the conversion at the remote computer (at the expense of a larger scriptblock) and just return the already converted date.</span>RoHeVehttp://www.blogger.com/profile/02418913823290203666noreply@blogger.com0