SIP Testing and Troubleshooting with sipsak

When testing the Internet, there are several key tools we use in troubleshooting: one of them is ping. To verify a particular IP address is operational we “ping 192.168.0.1” from the command line to see if we get an answer back, letting us know that the system we are pinging and the network itself is operational at least through Layer 3 – the Network Layer. Certainly this is also usable in VoIP networks. But what if I want to go a step further and test the “control plane” of VoIP – that uses SIP (Session Initiation Protocol)?

sipsak is a lightweight, command-line SIP testing and troubleshooting tool used by VoIP engineers and administrators. It allows you to send custom SIP requests—such as OPTIONS, REGISTER, INVITE, etc.—to a SIP server or endpoint for monitoring and debugging purposes.

What Can sipsak Do?

  • Send SIP OPTIONS pings to test if a SIP server is responsive. This is known as a SIP ping. You can read more about this here.
  • Send SIP REGISTER requests to test SIP registration.
  • Simulate basic SIP calls (e.g., INVITE, BYE) for testing signaling.
  • Perform load testing by sending many SIP requests rapidly.
  • Retrieve SIP server capabilities and headers in responses.

Typical Use Case Example

Check if a SIP server is reachable and responding – executing a SIP ping to the VoIP Switch:

bash
sipsak -s sip:sipserver.example.com

Send SIP OPTIONS to a specific user – executing a SIP ping to a user:

bash
sipsak -s sip:1000@sip.example.com

Specify a custom IP and port – executing a SIP ping to an IP address and port on any VoIP device on the network:

bash
sipsak -s sip:server.com -i 192.168.1.50 -p 5060

Features Summary

FeatureDescription
SIP OPTIONS supportBasic SIP ping / health check
AuthenticationSupports digest authentication
Custom headersAllows crafting of SIP headers
Looping/load testsSend requests repeatedly to test load-handling
LightweightFast, CLI-based, easy to script in automation

Installation

  • Linux (Debian/Ubuntu): sudo apt install sipsak
  • macOS (via Homebrew): brew install sipsak
  • Windows:
    There’s no official Windows build, but you can:
    • Use it in WSL (Windows Subsystem for Linux).
    • Compile from source with Cygwin.
    • Use a SIP tool like PJSIP or SIPp instead.
This is the sipsak -h output displaying the command line options for sipsak.

Using sipsak in the Real World

I can think of two examples of where I would want to use this tool:

  • A simple script that checks on the health of my VoIP Switch
  • A more complex script that also measures response time, sends email alerts, or logs to a file

SIP Ping Script Using sipsak

Here’s a real-world SIP ping script using sipsak that you can run from a Linux or macOS terminal (or WSL on Windows). This script will:

  • Send a SIP OPTIONS ping to a SIP server
  • Check if the server responds with 200 OK
  • Log the result with a timestamp
bash
#!/bin/bash

# SIP server to ping
SIP_SERVER="sip:sip.example.com"
# Interface IP to use (optional)
LOCAL_IP="192.168.1.100"

# Send SIP OPTIONS ping
RESPONSE=$(sipsak -s "$SIP_SERVER" -i "$LOCAL_IP" -vvv 2>&1)

# Check for SIP 200 OK in the response
if echo "$RESPONSE" | grep -q "200 OK"; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - SIP server responded: 200 OK"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR: No 200 OK from SIP server"
echo "Response was:"
echo "$RESPONSE"
fi

How to Use the Script

  1. Replace sip:sip.example.com with your actual SIP URI.
  2. Replace 192.168.1.100 with your source IP address if needed (or remove -i if not required).
  3. Save as sip_ping.sh, then make it executable:
bash
chmod +x sip_ping.sh
./sip_ping.sh

Optional: Loop It Periodically

To run the check every 60 seconds (you can certainly change this time):

bash
while true; do
./sip_ping.sh
sleep 60
done

Or add it as a cron job for long-term monitoring/logging.

Enhancing our SIP Ping Script with Logging and Alerts

  • Sends a SIP OPTIONS ping
  • Logs to a file
  • Measures round-trip time
  • Sends an email alert if the server doesn’t respond with 200 OK
bash
#!/bin/bash

# CONFIGURATION
SIP_SERVER="sip:sip.example.com"
LOCAL_IP="192.168.1.100"
LOG_FILE="/var/log/sip_ping.log"
ALERT_EMAIL="admin@example.com"
HOSTNAME=$(hostname)

# FUNCTION TO SEND ALERT
send_alert() {
SUBJECT="SIP Ping Alert from $HOSTNAME"
MESSAGE="[$(date '+%Y-%m-%d %H:%M:%S')] SIP ping to $SIP_SERVER failed. No 200 OK response received."
echo "$MESSAGE" | mail -s "$SUBJECT" "$ALERT_EMAIL"
}

# PERFORM PING AND MEASURE TIME
START_TIME=$(date +%s%3N)
RESPONSE=$(sipsak -s "$SIP_SERVER" -i "$LOCAL_IP" -vvv 2>&1)
END_TIME=$(date +%s%3N)

# Calculate round-trip time
RTT=$((END_TIME - START_TIME))

# CHECK RESPONSE
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
if echo "$RESPONSE" | grep -q "200 OK"; then
echo "$TIMESTAMP - SUCCESS: 200 OK from $SIP_SERVER - RTT ${RTT}ms" >> "$LOG_FILE"
else
echo "$TIMESTAMP - ERROR: No 200 OK from $SIP_SERVER - RTT ${RTT}ms" >> "$LOG_FILE"
echo "$RESPONSE" >> "$LOG_FILE"
send_alert
fi

Setup Instructions

  1. Install sipsak and mail (if not already installed): sudo apt install sipsak mailutils
  2. Make the script executable: chmod +x sip_ping_monitor.sh
  3. Set up a cron job (optional): crontab -e Add this line to run every 5 minutes: */5 * * * * /path/to/sip_ping_monitor.sh

Email Requirements

  • You must have mailutils configured with a working MTA (e.g., postfix or msmtp).
  • You can test email functionality with: echo "test" | mail -s "test subject" your@email.com

Conclusion

If you work on VoIP networks that all use the SIP protocol for the control plane, you certainly can use ping for troubleshooting, but you also need a tool that verifies the control plane of VoIP – SIP. the sipsak tool is a great way to to this.


Comments are welcomed below from registered users.  You can also leave comments at our Discord server

If you would like to see more content and articles like this, please support us by clicking the patron link where you will receive free bonus access to courses and more, or simply buying us a cup of coffee!

Scroll to Top