Last active
May 16, 2024 20:58
-
-
Save jakedolan443/6dda823fd86bc86b2c3291c5695a0924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# File: CallSignal.sh | |
# Author: Jake Dolan ([email protected]) | |
# | |
# Purpose: Listen for incoming SIP signals on | |
# a specified address and send a | |
# TCP signal to another address when | |
# detected. (Optional) Can be disabled | |
# for specified time periods. | |
# | |
# Should be time-disabled in unused periods | |
# to reduce writing load on the filesystem. | |
# This is PARTICULARLY important on Raspberry | |
# Pis running on SD cards. This can be done | |
# using the ENABLED_FROM and DISABLED_FROM | |
# variables. | |
INTERFACE="eth0" | |
LISTEN_PHONE_ADDRESS="192.168.1.146" | |
CALL_SERVER_ADDRESS="192.168.1.200" | |
CALL_SERVER_PORT=16727 | |
ENABLED_FROM=21600 # 21600 seconds = 6AM | |
DISABLED_FROM=72000 # 72000 seconds = 8PM | |
# Script will be inactive outside of these times. | |
function sendCallSignal () { | |
signal_time=$(date +'%H:%D') | |
signal=$(cksum <<< "C26SX:95AFC-$signal_time" | cut -f 1 -d ' ') | |
echo "$signal" | nc -q 1 $CALL_SERVER_ADDRESS $CALL_SERVER_PORT | |
} | |
while true; do | |
# Convert the current time to seconds within the day (of 86400+) | |
curr_time=$(date +"%H:%M" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }') | |
if [ "$ENABLED_FROM" -lt "$curr_time" ]; then | |
# Flush log files | |
rm -rf /tmp/*.pcapng | |
# Capture SIP request messages using Tshark | |
tshark -n -a duration:100 -M 10000 -i $INTERFACE -Y "(sip.Method==INVITE)&&(ip.dst==$LISTEN_PHONE_ADDRESS)" -T fields -e ip.src -e ip.dst -l | | |
while read -r src_ip domain_name query_type; do | |
sendCallSignal | |
done | |
else | |
sleep 5 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment