Clicky

20221226

Fritz!Box - telephony logging

This post describes a simple (!) data logging system for those with a Fritz!Box that is also used for wired/DECT telephony.

Many Fritz!Box models have a build-in method to share the telephony data. The data can be obtained through a TCP port on the Fritz!Box. The data sharing port is (fixed to) port 1012. To enable/disable the sharing, dial the next with a phone that is connected to the Fritz!Box:

Enable data sharing:  #96*5*

Disable data sharing: #96*4*


To check if the data sharing is working, use Telnet:


C:\> telnet {IP address of Fritz!Box} 1012

 

You will see a black screen. Make a phone call to the Fritz!Box and you will see something like this:

 

26.12.22 14:37:00;RING;0;0610901234;+31123456091;SIP0;
26.12.22 14:37:01;DISCONNECT;0;0;
26.12.22 14:37:18;CALL;0;0;+31123456091;0610901234;SIP0;
26.12.22 14:37:25;CONNECT;0;0;0610901234;
26.12.22 14:37:34;DISCONNECT;0;8;

 

RING = incoming call

CALL = outgoing call 

CONNECT =  pick up of a phone connected to the Fritz!Box

DISCONNECT = hang up of a phone connected to the Fritz!Box

 

Now, to log data to a log file use this Powershell script:


<#
   
    Date: 26-Dec-2022
    Purpose: Read Fritz!Box' phone data
   
    TCP port: 1012
    Enable port : Dial #96*5*
    Disable port: Dial #96*4*

#>

$fritzBox  = "{Fritz!Box IP address}"
$fritzPort = 1012
$logFile   = "{path to}\Fritz!BoxPhoneData.log"

$now = get-date -Format s
write-output "$now;--- Start Fritz!Box telephony data logging..." | out-file $logFile -append

while ($true) {

    $tcpClient = new-Object System.Net.Sockets.TcpClient($fritzBox,$fritzPort)
    $tcpStream = $tcpClient.GetStream()
    $reader = New-Object System.IO.StreamReader($tcpStream)  
   
    while ($tcpClient.Connected
    {
 
        while ($tcpStream.DataAvailable
        {
                   
            $response = $reader.ReadLine()
            $now = get-date -Format s
            write-output "$now;$response" | out-file $logFile -append
            write-host "$now;$response"
           
        }

        #--- Poll port every 5s...
        Start-Sleep 5

    }
   
    #--- Recover from a connection loss, e.g. Fritz!Box reboot...
    Start-Sleep 60

}    


You may use a tool like NSSM to create a Windows Service. Then the script will run in the background and it will log all phone calls to the log file.

20221030

modifyINI.ps1: an INI file modification script

The next script modifies one value in one section in an INI file. The INI filename stays the same. No input validation, no backup, no fancy command line parsing, no help, no nothing...

The  regexp's are stolen from: https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-any-ini-file/

<#

    Script: modifyINI.ps1
    Purpose: Change values in INI files
    Date: 20-Oct-2022
    Version: 0.1
 
    Usage: 
 
PS C:\> modifyINI.ps1 "INI file" "[Section]" "Key" "New value" 
   
    --- c:\temp\test.ini -------------------
    [System]
    Colors=256
    memSize=20MB
    cpuCores=4
    ----------------------------------------
       
    PS C:\> modifyINI.ps1 "c:\temp\test.ini" "[System]" "memSize" "35MB"

    --- c:\temp\test.ini -------------------
    [System]
    Colors=256
    memSize=35MB
    cpuCores=4
    ----------------------------------------

#>

    if ($args.count -NE 4) {Exit}
   
    $iniFile    = $args[0]
    $srcSection = $args[1]
    $srcKey     = $args[2]
    $newVal     = $args[3]
 
    $tabChr     = ""        #--- Ident for val/var lines
    $spaceChr   = ""        #--- Space before/after "=", for readability.
    $section    = $NULL
   
    $srcFile = get-content $iniFile
    $tmpFile = New-TemporaryFile


    foreach ($line in $srcFile) {
       
        $bareLine = $line.trim()
       
        if ($bareLine -MATCH "^\[(.+)\]") {             #--- [Section]...
         
            $section = $bareLine
           
        } ELSEIF ($bareLine -MATCH  "(.+?)\s*=(.*)") {  #--- key=val...
         
            $key = $bareLine.split("=")[0].trim()
            $val = $bareLine.split("=")[1].trim()
       
            if (($srcSection -EQ $section) -AND ($srcKey -EQ $key)) {
               
                $bareLine = "$tabChr$key$spaceChr=$spaceChr$newVal"
               
            } ELSE {
               
                $bareLine = "$tabChr$key$spaceChr=$spaceChr$val"
               
            }
       
        } #--- ELSE do nothing $bareLine...
       

        write-output "$bareLine" | out-file $tmpFile -append
       
    }    
   
    copy-item $tmpFile $iniFile -force
    remove-item $tmpFile -force

   

20220806

Luidsprekerdoek vervangen

Ik had een paar tweedehands Mission speakers gekocht. De speakers zelf zijn picobello, maar de frontjes hadden in de zon gestaan en zijn verkleurd. Dus zelf de stoute schoenen aangetrokken om het luidspreker doek te gaan vervangen. Luidsprekerdoek besteld, maar antraciet is niet de juiste kleur. Dus even wachten op zwarte stof.

Ik besefte dat ik nul ervaring had met luidsprekerdoek vervangen *en* ik had nog een setje Sony boxen staan waar het doek ook niet helemaal fris meer was besloten om eerst maar eens ervaring op te doen


Doek verwijderd van frame en nieuw doek uitgeknipt:


De zijde aan de bovenkant is hier al geplakt met Bison Tix. Om iets van voorspanning op het doek tijdens het plakken te krijgen en het doek goed te kunnen plakken, met ouderwetse knijpers en een dikke muismat een plak-span inrichting gemaakt:


Alle vier de kanten geplakt. Dit was makkelijk. Nu de hoeken nog afwerken.



De hoeken vereisen wat lijm, fingerspitzengefühl en geluk. Het is de kunst om de rekbaarheid van het doek in de hoeken te gebruiken om de stof de hoek om te laten plooien.

Hierbij het resultaat (links). Het "vlekje" is de (glimmende) tweeter, de nieuwe stof is een beetje doorzichtig.



20220515

Add WiFi profile by script

 Use this Powershell script to add an SSID session to your Windows WiFi settings.

Usage (in elevated command console):

C:\> Powershell -file addSSID.ps1 {SSID} {Password}

param(
    [string]$SSID,
    [string]$PSK
)
$guid = New-Guid
$HexArray = $ssid.ToCharArray() | foreach-object { [System.String]::Format("{0:X}", [System.Convert]::ToUInt32($_)) }
$HexSSID = $HexArray -join ""
@"
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>$($SSID)</name>
    <SSIDConfig>
        <SSID>
            <hex>$($HexSSID)</hex>
            <name>$($SSID)</name>
        </SSID>
    </SSIDConfig>
   
    <connectionType>ESS</connectionType>
    <connectionMode>auto</connectionMode>
    <MSM>
        <security>
            <authEncryption>
<authentication>WPA2PSK</authentication>
                <encryption>AES</encryption>
                <useOneX>false</useOneX>
            </authEncryption>
            <sharedKey>
                <keyType>passPhrase</keyType>
                <protected>false</protected>
                <keyMaterial>$($PSK)</keyMaterial>
            </sharedKey>
        </security>
    </MSM>
    <MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
<enableRandomization>false</enableRandomization>
<randomizationSeed>1451755948</randomizationSeed>
    </MacRandomization>
</WLANProfile>
"@ | out-file "$($ENV:TEMP)\$guid.SSID"

netsh wlan add profile filename="$($ENV:TEMP)\$guid.SSID" user=all

remove-item "$($ENV:TEMP)\$guid.SSID" -Force

Real Time Web Analytics