I started a script that run on a linux satellite receiver and run the 'dvbsnoop' tool. I need help to finish the script because i do not know hot to handle the results from the 'dvbsnoop' tool.
#!/bin/bash
# Asign to variable 'b' the service reference for wanted TV channel
b="1:0:1:5A:65:1:FFFF0000:0:0:0:"
# Acces the web interface and set requested TV channel
wget -q -O - "http://127.0.0.1/web/zap?sRef=$b"
# Sniff data stream with dvbsnoop tool (1 packet and nohexdumpbuffer)
dvbsnoop -n 1 -nph 1
#
# HELP ME HERE
#
# 'dvbsnoop' will return a list of CA_system_ID and other informations
# It could be one CA_system_ID, more than one or none.
# Example: CA_system_ID: 6272 (0x1880), CA_system_ID: 1723 (0x06bb), CA_system_ID: 6260 (0x1874)
# The only information that i'm interested is between brackets: (0x1880), (0x06bb), (0xXXXX), etc
#
# the variable 'b' should then be stored in a filename.
# (preferably named after the value of CA_system_ID, for example CAiD_0x1880.txt).
# The script should creates the file if not present, otherwise appends to it.
#
# If 'dvbsnoop' return more than one CA_system_ID then the variable 'b' should be added in multiple files.
#
# The text #SERVICE must preceded de content of variable 'b' in the file.
#
# Example:
# File name: CAiD_0x1880.txt
# File content after run of the script: #SERVICE 1:0:1:5A:65:1:FFFF0000:0:0:0:
#
After running the 'dvbsnoop -n 1 -nph 1
' the output looks like this:
dvbsnoop V1.4.56 -- https://github.com/OpenVisionE2/dvbsnoop
------------------------------------------------------------
SECT-Packet: 00000001 PID: 1 (0x0001), Length: 36 (0x0024)
Time received: Sat 2022-01-08 18:38:44.926
------------------------------------------------------------
PID: 1 (0x0001) [= assigned for: ISO 13818-1 Conditional Access Table (CAT)]
Guess table from table id...
CAT-decoding....
Table_ID: 1 (0x01) [= Conditional Access Table (CAT)]
section_syntax_indicator: 1 (0x01)
(fixed): 0 (0x00)
reserved_1: 3 (0x03)
Section_length: 33 (0x0021)
reserved_2: 262143 (0x3ffff)
Version_number: 5 (0x05)
current_next_indicator: 1 (0x01) [= valid now]
Section_number: 0 (0x00)
Last_Section_number: 0 (0x00)
MPEG-DescriptorTag: 9 (0x09) [= CA_descriptor]
descriptor_length: 4 (0x04)
CA_system_ID: 6145 (0x1801) [= Kudelski SA]
reserved: 7 (0x07)
CA_PID: 129 (0x0081)
MPEG-DescriptorTag: 9 (0x09) [= CA_descriptor]
descriptor_length: 4 (0x04)
CA_system_ID: 6272 (0x1880) [= Kudelski SA]
reserved: 7 (0x07)
CA_PID: 131 (0x0083)
MPEG-DescriptorTag: 9 (0x09) [= CA_descriptor]
descriptor_length: 4 (0x04)
CA_system_ID: 1723 (0x06bb) [= Irdeto]
reserved: 7 (0x07)
CA_PID: 134 (0x0086)
MPEG-DescriptorTag: 9 (0x09) [= CA_descriptor]
descriptor_length: 4 (0x04)
CA_system_ID: 6260 (0x1874) [= Kudelski SA]
reserved: 7 (0x07)
CA_PID: 135 (0x0087)
CRC: 1088558619 (0x40e2161b)
==========================================================
The point of this script is to sort and store in files TV channels that use the same encryption systems. How i mentioned, this script will run on a Linux satellite TV receiver and the resulting file will be used as a Favorite TV channels Lists. If i insert in the receiver a smartcard with CAiD 1880 then i would like to access only TV channels that are using 1880 encription.
This might be what you want:
#!/bin/bash
b='1:0:1:5A:65:1:FFFF0000:0:0:0:'
re='CA_system_ID:.*\((0x[[:xdigit:]]+)\)'
dvbsnoop -n 1 -nph 1 |
while read -r line; do
if [[ $line =~ $re ]]; then
echo "#SERVICE $b" >> "CAiD_${BASH_REMATCH[1]}.txt"
fi
done