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.

Real Time Web Analytics