Clicky

20171210

Detect public IP address change and send email

I really, really should stop scripting in VBscript. It is boo, boo and is already 10+ years replaced by Powershell. Having said that, I needed a simple method to detect a change on a dynamic assigned public IP address. 

Note: for the SendMail function check this post.

This is the script:

    on error resume next

    dim fso, wsh
    set fso = Createobject("scripting.filesystemobject")
    set wsh = CreateObject("wscript.shell")

    const key = "HKEY_CURRENT_USER\SOFTWARE\getPublicIP\publicIPaddress"
    if isnull(wsh.regRead(key)) then wsh.Regwrite key,"0.0.0.0", "REG_SZ"
    Err.Clear
  
    '--- Get public IP address...
    Set objHTTP = CreateObject("Msxml2.XMLHTTP")
    objHTTP.open "GET", "http://ipinfo.io/json", False
    objHTTP.send
    t = split(Cstr(objHTTP.responseText),chr(34))
    currentIPaddress = t(3)

    '--- Read previous IP address...
    previousIPaddress = wsh.regRead(key)

    '--- Compare and when changed, send email with new IP address...
    if currentIPaddress <> previousIPaddress then

        s = "Public IP address has changed." & vbCrLF
        s = s  & "Previous IP address: " & previousIPaddress & vbCrLf
        s = s  & "Current IP address : " & currentIPaddress & vbCrLf
        wscript.echo "Sending email:" &vbCrLf & s
      
        if sendmail(s) = 0 then
            wscript.echo "*** Succesfully sent email."
            wsh.Regwrite key, currentIPaddress, "REG_SZ"
            wsh.LogEvent 0,s
        else
            wscript.echo "*** Error sending email"
        end if  
      
    else
        wscript.echo "*** Public IP address not changed: " & currentIPaddress
    end if



20171116

Month calendar with vertical outlined weeks

VBscript is still boo, boo but some things are really simple to build in VBscript. Here is a calendar program with vertical outlined weeks, week numbers and even consideration for leap years (until the year 2100).

Use:

 C:\Scripts\> cscript //nologo calendar.vbs MM-YYYY

--- 8< ---------------------------------------------

Function Print(s)
    if len(s)=1 then wscript.stdout.write " "
    wscript.stdout.write s & "  "
end Function

Datum        = wscript.arguments(0)
dayOfTheWeek = DatePart("w",datum)
weekNumber   = DatePart("ww",datum, vbSunday ,vbFirstFourDays)
ArrayStart   = dayOfTheWeek - ((dayOfTheWeek -1) * 2)
monthNumber  = Month(Datum)
WeekDays     = Array("Su","Mo","Tu","We","Th","Fr","Sa")
DaysInMonth  = Array(31,28,31,30,31,30,31,31,30,31,30,31)
monthNames   = Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

'--- Adjust values...
if DaysInMonth(monthNumber-1) + (dayOfTheWeek-1) > 35 then NuOfWeeks = 6 else NuOfWeeks = 5
if Year(Datum) mod 4=0 then DaysInMonth(1)=29

wscript.echo vbCrLf & "Calendar of: " & monthNames(monthNumber-1) & "-" & year(Datum) & vbCrLf
'--- Print weeknumbers
Print " "
for w = 0 to (NuOfWeeks-1) : Print (weekNumber + w) : next
wscript.echo ""
for w = 0 to (NuOfWeeks) : Print "--" : next
wscript.echo ""

'--- Print calendar...
Column = 0
for i = ArrayStart to ArrayStart + 6
    Print Weekdays(Column)
    Column = Column + 1
    for j = 0 to 5
        dayNumber = i + (j * 7)
        if (dayNumber >= 1) and (dayNumber <= DaysInMonth(monthNumber-1)) then Print DayNumber else Print " "
    next
    wscript.echo ""
next
 

20171110

Automatic emailing of your scanned documents


Some document scanners have the capability to send an email with the scanned document attached. Maybe your scanner can only store scanned files on a NAS, network share or in a folder on your computer. In that case, the next script will detect new scans and email them to you.

Yes, it is VBscript and that is boo, boo, as I mentioned before. However, the email method here, although deprecated, is also used by PowerShell users since it can deal with implicit SSL.

This post consists of two parts:
1. The script
2. A method to start the script automatically if the user is not logged on

The script


Copy & paste all the lines between the markers to Notepad or so and save the script as "MailScan.vbs". Then modify the Recipient with your email address. Modify the SMTP parameters. You might want to create a Gmail address specifically for sending scans. Finally, configure the folder where your scanner stores the scans.

--- 8< -------------------------------------
on error resume next

sub SendMail(Recipient, PDFfile)
 
    Dim objEmail
    Set objEmail        = CreateObject("CDO.Message")

    objEmail.From         = "scannername@yourdomain.com"
    objEmail.To         = Recipient
    objEmail.Subject     = "Scanned document from scanner {scannername/location}"
    objEmail.Textbody     = now() & ", this email contains a scanned document from scanner {scannername/location}: " & PDFfile

'--- When you host your own mailserver, use this:   
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")             = 2
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")         = "192.168.1.13" ' IP address of your emailserver
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")         = 0
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")     = 1
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")        ="smtpaccount@yourdomain.com"
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")        ="{Password}"
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")     = 25
   
'--- Or you can use Google's SMTP service:   
    REM objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")        = aGoogleAccount
    REM objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")        = theGooglePassword
    REM objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")         = "smtp.gmail.com"
    REM objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")         = 1
    REM objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")     = 1
    REM objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")             = 2
    REM objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")     = 465

    objEmail.AddAttachment PDFfile
    objEmail.Configuration.Fields.Update
   
    objEmail.Send

    SendMail = Err
   
end sub

'--- Main ----------------------------------------------------------------------------------------------------

const emailReceipient = "your@email_addre.ss"
const intInterval = "5" 'check every 'intInterval' seconds for new file(s)...

dim fso
set fso=CreateObject("scripting.FileSystemObject")

'--- Split up the drive and the scan folder. Needed for WMI...
strDrive     = "M:"
strFolder    = "\\ProgramData\\MailScan\\"

wscript.echo "Scanning folder for files to arrive: " & replace(strDrive,"\\","\") & replace(strFolder,"\\","\")

'--- Set up event WMI handler...
Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2" )
strQuery =  _
    "Select * From __InstanceOperationEvent"                             _
    & " Within "                                     & intInterval         _
    & " Where Targetinstance Isa 'CIM_DataFile'"                         _
    & " And TargetInstance.Drive='"                 & strDrive &  "'"    _
    & " And TargetInstance.Path='"                     & strFolder & "'"
Set colEvents = objWMIService. ExecNotificationQuery (strQuery)

'--- Loop endless with an interval of 'intInterval'...
Do    
    Set objEvent = colEvents.NextEvent()
    Set objTargetInst = objEvent.TargetInstance

    Select Case objEvent.Path_.Class
        Case "__InstanceCreationEvent"
            f=objTargetInst.Name
            WScript.Echo "*** New file received: " & f
           
            wscript.echo "*** emailReceipient : " & emailReceipient
            wscript.echo "*** Filename: " & f
           
            '--- Check for PDF file and email that...
            if Instr(lcase(f),".pdf") > 0 then
                call SendMail(emailReceipient,f)
                wscript.echo "*** Emailing of PDF file done"
                if Err <> 0 then wscript.echo "*** Error sending mail. Errormessage: 0x" & hex(Err) & " - " & Err.Description
            end if   
           
            '--- You can delete the PDF file after emailing. Uncomment the next lines...
            'fso.DeleteFile f,true
            'wscript.echo "File deleted: " & f
    End Select
Loop

--- 8< -------------------------------------

Testing the script

To test if everything works fine we manually start the script:

  c:\Scripts> cscript //nologo MailScan.vbs

Make a scan, or just copy a PDF file in the scanfolder, and check the output on the screen. If all goes well you see:

Scanning folder for files to arrive: M:\ProgramData\MailScan\
*** New file received: m:\programdata\mailscan\manual_en - copy (2) - copy - copy - copy.pdf
*** emailTo : your@email_addre.ss
*** Filename: m:\programdata\mailscan\manual_en - copy (2) - copy - copy - copy.pdf
*** Emailing of PDF file ready


If there is an error sending the PDF you will see:

Scanning folder for files to arrive: M:\ProgramData\MailScan\
*** New file received: m:\programdata\mailscan\manual_en - copy (5).pdf
*** emailTo : your@email_addre.ss
*** Filename: m:\programdata\mailscan\manual_en - copy (5).pdf
*** Emailing of PDF file done
*** Error sending mail. Errormessage: 80040211 - The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response
was not available


The Windows Service

 

You want to have this service 24x7 available, even when you are not logged on to your computer. When we use script in a Windows Service we can run the script automatically in the background. We need a utility to configure this for you: the Non-Sucking Service Manager. Download NSSM here.

Start NSSM and configure the scan service:

  C:\Scripts> nssm install MailScan

Configure the next two tabs. Configure in "Arguments" the folder where the script is stored.


When all is entered correctly press the "Install Service" button. We can start the service:

  C:\Scripts> net start MailScan

Now make a scan and check your mailbox!

20171107

Powershell ROCA test

This Powershell script tests a TPM based Public Key for the ROCA vulenerability (CVE-2017-15361).

Based on: https://github.com/crocs-muni/roca/tree/master/csharp

Prequisites:
- Bouncy Castle crypto DLL (https://www.bouncycastle.org/csharp/index.html).
- Windows 8, 8.1 or 10 OS (e.g. a USB stick with Windows to Go)

The comments below explains how to create a TPM based Public Key file.

--- 8< --------------------
<#
    Date:             5-Nov-2017
    Description:     This script tests if a Public Key is vulnerable for ROCA
                    Use a TPM based CSR or CRT, extract the Public Key and test
    Prerequisite:    Bouncy Castle DLL (http://www.bouncycastle.org/csharp/)
   
>>> Create and extract a Public Key on Windows 8, 8.1 and 10 through a CSR:
(if a PC runs W7 or older or does note even have a hard disk, use Windows-to-Go from USB)

1. Create TPMCSR.inf
    --- 8< -----------------------
    [NewRequest]
    Subject = "E=IFXTPMVSC"
    KeyLength = 2048
    Exportable = FALSE
    UserProtected = FALSE
    MachineKeySet = FALSE
    Providername = "Microsoft Platform Crypto Provider"
    ProviderType = 1
    RequestType = PKCS10
    KeyUsage = 0x80
    KeySpec=1
    --- 8< -----------------------
   
2. Create CSR:
    C:\> certreq -new -f TPMVSC.inf TPMCSR.csr >nul

3. Extract Public Key with OpenSSL:
    openssl.exe req -in TPMCSR.csr -noout -pubkey -out TPMCSR.csr-pubk.pem   
   
4. Configure the filename in this script and run the script
    c:\scripts> powershell -file testROCA.ps1 TPMCSR.csr-pubk.pem   
    Vulnerable: True
   
>>> Using a TPM based certificate:
1. Extract the Public Key with OpenSSL:
    openssl.exe x509 -in TPMCSR.crt -noout -pubkey -out TPMCSR-pubk.pem   
   
2. Configure the filename in this script and run the script
    c:\scripts>powershell -file testROCA.ps1
    Vulnerable: True
   
>>> Example Public Keys:
Vulnerable Pubk:
    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQECWSe1K6XmjIySaLuSGPN2
    c2FMplQY9HRbFDzU7lP5SRyaDhwvI6lRYwav+/OGZ7hxvAzILmD1uxqfoVpWcadl
    yfIblYfYARWWQ3Kjg8iDsNy/bHdXBrMer/Pj/UiFWaCM3qIPmpfExZtrio7spFfU
    qCDUlQn3WTNjAryho2kLCAkYEfhY8ujOpaYjVa1uBB0ZNe2lkom1l2g7c+JleudL
    /8dg5NUTzIfbk1WRjqoI05i75faDXchxJSEbmzazoLxwuZOmyz99LLQGHec9uXLJ
    Qq35lVtv5M2Q8A0IiuwErx9e/5HyGvXtRGF8fbgJP5U2bbJlgMSvOZ3rlPmxQTBb
    4QIDAQAB
    -----END PUBLIC KEY-----

NOT vulnerable Pubk:
    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr2WWdhl/HbBtp6wRGgoO
    wXW4t+8HGS/80fa4VMMneF8af9PbfaRc1KMbKy5c4Ngjpo4oyK3xdHMWvszh/ldo
    BkA5rSBiJgyNGjTgWG3Om8EwkPzJ+4uLLAjtOujWGymBimaWiafZwdqwU7VX+40/
    nET6rT4YxV5zmwDTyRJlWLyOmAzSrzdxJu9bE3QTZ3S4vTcOPBwUnbOVyPmWlrYo
    sQWUb+ogEG/iTRA6wGJmGpJI6MP2KOALMI0zlTqr5VUTLiGOdO9LV4cWtP5880Do
    5gSjGb9umVHhlCYB00KRAy21SZnQnl0Dbd41RK01JWu7l9Xj//04Fmwh6ukZlUiF
    OwIDAQAB
    -----END PUBLIC KEY-----
#>

if ($args.count -ne 1) {
    cls
    write-host "*** Usage: powershell -file testROCA.ps1 {public key file}"
    Break
    }
   
$pubKfile = $args[0]
if (-not (Test-Path $pubKfile)) {
    write-host "*** File not found."
    Break
}
   
add-type -path ".\BouncyCastle.Crypto.dll"

[Org.BouncyCastle.Math.BigInteger[]] $markers = @(
            "6",
            "30",
            "126",
            "1026",
            "5658",
            "107286",
            "199410",
            "8388606",
            "536870910",
            "2147483646",
            "67109890",
            "2199023255550",
            "8796093022206",
            "140737488355326",
            "5310023542746834",
            "576460752303423486",
            "1455791217086302986",
            "147573952589676412926",
            "20052041432995567486",
            "6041388139249378920330",
            "207530445072488465666",
            "9671406556917033397649406",
            "618970019642690137449562110",
            "79228162521181866724264247298",
            "2535301200456458802993406410750",
            "1760368345969468176824550810518",
            "50079290986288516948354744811034",
            "473022961816146413042658758988474",
            "10384593717069655257060992658440190",
            "144390480366845522447407333004847678774",
            "2722258935367507707706996859454145691646",
            "174224571863520493293247799005065324265470",
            "696898287454081973172991196020261297061886",
            "713623846352979940529142984724747568191373310",
            "1800793591454480341970779146165214289059119882",
            "126304807362733370595828809000324029340048915994",
            "11692013098647223345629478661730264157247460343806",
            "187072209578355573530071658587684226515959365500926"
)

[Org.BouncyCastle.Math.BigInteger[]] $primes = @( 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167 )

[System.IO.TextReader] $reader = [System.IO.File]::OpenText($pubKfile)

[Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters] $rsaKeyParameters = [Org.BouncyCastle.OpenSsl.PemReader]::new($reader).ReadObject()

$isVulnerable = $true
for ($i=0; $i -lt $primes.length;$i++)
{
    if ([Org.BouncyCastle.Math.BigInteger]::One.ShiftLeft($rsaKeyParameters.Modulus.Remainder($primes[$i]).IntValue).And($markers[$i]).Equals([Org.BouncyCastle.Math.BigInteger]::Zero))
        {
            $isVulnerable=$false
            break
        }
}

write-host "Vulnerable (
$pubKfile):" $isVulnerable

20170723

BMW R1200RT, van model Sahara naar model Touring

De BMW R1200RT modellenreeks 2010-2014 zijn fantastische motoren met slechts een paar ontwerp foutjes. Een probleem, die opgelost is in de R1200 LC, is de hoge temperatuur in de kuip. Dit wordt veroorzaakt door de oliekoeler die onder de koplamp gemonteerd is. Door de onderdruk in de kuip wordt als het ware de (warme) lucht die uit de oliekoeler komt de kuip in gezogen (zeker met het grote Wunderlich scherm). Hierdoor is de temperatuur daar 6 a 7 graden hoger. 

Ik had al eens aan de deskundigen van de BMW RT Forum gevraagd hoe dat op te lossen. Na uitgebreide feedback heb ik besloten om de koeler naar beneden te verplaatsen. Na het zien van de oliekoeler van de R1200R heb ik de stoute schoenen aangetrokken en ben ik op onderdelenjacht gegaan. Op eBay stond een tweedehands R1200R koeler + slangen te koop. 

R1200R koeler + slangen
 Het "pikkie" bovenop de koeler valt in een uitsparing in de kap die voor de aandrijfriem van de dynamo zit.
Kap R1200R (links, met uitsparing voor de koeler) en R1200RT
De beugel wordt op de drie onderste bevestigingspunten van de kap gemonteerd. Op de beugel wordt de koeler geschroefd.

Oliekoeler bevestigingsbeugel




 Gemonteerd ziet het er dan zo uit:
Vervang de bestaande olieleidingen voor die van R1200R. Je kan gebruik maken van bestaande montage punten op het motorblok.
R1200R olieleiding rechts

 
R1200R olieleiding links
Een van de uitdagingen was de beugel waarop de zijpanelen bevestigd wordt. Die zit in de weg en ik heb daar een beugel voor gemaakt.
Beugel
Nadeel is dat de panelen ongeveer 3cm meer naar "buiten" staan. Ook moeten er beugeltjes gemaakt worden om het positie verschil op te vangen.
Het past nu allemaal we maar het is niet een geweldig mooie oplossing. In de herfst ga ik de twee bevestigings beugels inkorten zodat de panelen weer op hun originele plek zitten.

Kosten:
  • Oliekoeler + slangen (eBay): $258 (EUR235)
  • Oliekoeler beugel: EUR23
  • Deksel: EUR40 
  • Lekkere koele lucht: onbetaalbaaar
Totaal: ongeveer EUR400.

Maar nu eerst de bergen in! Alle passen in Zwitserland en Oostenrijk zijn open!

UPDATE: Bij de Hornbach zag ik deze beugels liggen:
Verend en met een moer voor de beugel. Precies wat ik nodig heb!

Ik heb de twee bestaande "uithouders" voor de bevestiging van de fairing van de beugel geslepen, de beugel geschuurd en geschilderd en d.m.v. twee van die Hornbach beugels de fairing weer op de originele plaats gemonteerd.

Geheel gemonteerd ziet het er zo uit:


20170722

Een stofjas voor een oude baas

Veel mensen houden van muziek. Veel smartphones hebben voldoende geheugen om je hele muziek collectie op te slaan en af te spelen maar je kan ook genieten van on-line muziek. Hedendaagse muziek wordt digitaal opgeslagen en verstuurd en pas op je smartphone wordt de digitale informatie weer omgezet naar geluid.

Je kon vroeger natuurlijk muziek op de radio luisteren maar het was natuurlijk fijner als je zelf het tijdstip van je muziekkeuze kan bepalen. In de vorige eeuw is de platenspeler uit gevonden. De muziek wordt analoog (!) op een vinyl schijf van 30 cm/12 inch geperst. De analoge informatie wordt door middel van een naald afgetast en met versterker weer hoorbaar gemaakt.

Platenspeler (boven) en versterker (beneden)
Ik heb nog, ook vanuit nostalgische redenen, een prachtige platenspeler staan. Onlangs geheel gerestaureerd, voorzien van een nieuwe naald en opnieuw gekalibreerd. Dit baasje is ongeveer 35 jaar oud en werkt nog als nieuw. Bedenk eens een ding in je leven wat zo lang mee gaat en nog goed werkt...

Nu gebruik ik de platenspeler niet dagelijks en staat 'ie dus "stof te happen".  Platen en stof zijn vijanden. Daarom heeft mijn vriendinnetje met kunst en vlijt een mooie stofhoes gemaakt.
 
Platenspeler hoes
Als detail nog een muzikaal borduurtje toegevoegd.




Nu kan de platenspeler nog tijden mee en als ik nog eens een plaat afspeel komen de zoete herinneringen terug. Zoals de vader van Raymond (Everybody loves Raymond) al zei (tijdens het luisteren naar een krakerige jazzplaat):"Now that's music!"
Real Time Web Analytics