Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
spandspflow2pcap Namespace Reference

Data Structures

class  FaxPcap
 
class  SkipPacket
 
class  SpandspLog
 

Functions

 main (logname, pcapname)
 
 n2b (text)
 

Variables

bool EMPTY_RECOVERY = False
 
 IFP = namedtuple('IFP', 'date seqno data')
 
bool LOSSY = False
 

Detailed Description

Usage: ./spandspflow2pcap.py SPANDSP_LOG SENDFAX_PCAP

Takes a log from Asterisk with SpanDSP, extracts the "received" data
and puts it in a pcap file. Use 'fax set debug on' and configure
logger.conf to get fax logs.

Input data should look something like this::

    [2013-08-07 15:17:34] FAX[23479] res_fax.c: FLOW T.38 Rx     5: IFP c0 ...

Output data will look like a valid pcap file ;-)

This allows you to reconstruct received faxes into replayable pcaps.

Replaying is expected to be done by SIPp with sipp-sendfax.xml. The
SIPp binary used for replaying must have image (fax) support. This means
you'll need a version higher than 3.5.0 (unreleased when writing this),
or the git master branch: https://github.com/SIPp/sipp


Author: Walter Doekes, OSSO B.V. (2013,2015,2016,2019)
License: Public Domain

Function Documentation

◆ main()

main (   logname,
  pcapname 
)

Definition at line 239 of file spandspflow2pcap.py.

239def main(logname, pcapname):
240 with open(sys.argv[1], 'r') as infile:
241 log = SpandspLog(infile)
242
243 # with open(sys.argv[2], 'xb') as outfile: # py3 exclusive write, bin
244 create_or_fail = os.O_CREAT | os.O_EXCL | os.O_WRONLY
245 try:
246 fd = os.open(sys.argv[2], create_or_fail, 0o600)
247 except Exception:
248 raise
249 else:
250 with os.fdopen(fd, 'wb') as outfile:
251 pcap = FaxPcap(outfile)
252 for data in log:
253 pcap.add(data)
254
255
int main()
Definition eagi_proxy.c:107

References len(), and main().

◆ n2b()

n2b (   text)
Convert "aa bb cc" to bytearray('\xaa\xbb\xcc').

Definition at line 44 of file spandspflow2pcap.py.

44def n2b(text):
45 """
46 Convert "aa bb cc" to bytearray('\xaa\xbb\xcc').
47 """
48 return bytearray(
49 b16decode(text.replace(' ', '').replace('\n', '').upper()))
50
51
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)

References replace().

Referenced by SpandspLog.__iter__().

Variable Documentation

◆ EMPTY_RECOVERY

bool EMPTY_RECOVERY = False

Definition at line 38 of file spandspflow2pcap.py.

◆ IFP

IFP = namedtuple('IFP', 'date seqno data')

Definition at line 41 of file spandspflow2pcap.py.

Referenced by SpandspLog.__iter__(), and FaxPcap.add().

◆ LOSSY

bool LOSSY = False

Definition at line 37 of file spandspflow2pcap.py.