sipp 盲转脚本编写
时间: 2023-07-12 19:20:01 浏览: 217
SIP消息和sipp脚本编写
SIPp可以使用XML脚本来描述SIP会话。盲转是一种SIP功能,允许用户在不知道目标URI的情况下将呼叫转移到其他URI。下面是一个基本的SIPp盲转脚本示例:
```xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<!-- 定义变量 -->
<scenario name="Blind Transfer" description="Blind Transfer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<send retrans="500" trcount="1">
<![CDATA[
INVITE sip:user1@192.168.1.1 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.2:5060;branch=z9hG4bK12345
From: sip:user2@192.168.1.2;tag=12345
To: sip:user1@192.168.1.1
Call-ID: 12345@192.168.1.2
CSeq: 1 INVITE
Contact: sip:user2@192.168.1.2:5060
Content-Type: application/sdp
Content-Length: 0
]]>
</send>
<!-- 等待100 Trying响应 -->
<recv response="100" optional="true">
</recv>
<!-- 等待200 OK响应 -->
<recv response="200">
<!-- 提取From标头 -->
<check_from uri="sip:user2@192.168.1.2" />
<!-- 提取To标头 -->
<check_to uri="sip:user1@192.168.1.1" />
<!-- 提取Contact标头 -->
<check_contact />
<!-- 提取SDP信息 -->
<check_body content="audio" />
</recv>
<!-- 发送盲转请求 -->
<send retrans="500" trcount="1">
<![CDATA[
REFER sip:user3@192.168.1.3 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.2:5060;branch=z9hG4bK12346
From: sip:user2@192.168.1.2;tag=12345
To: sip:user1@192.168.1.1
Call-ID: 12345@192.168.1.2
CSeq: 2 REFER
Contact: sip:user2@192.168.1.2:5060
Refer-To: <sip:user3@192.168.1.3>
]]>
</send>
<!-- 等待202 Accepted响应 -->
<recv response="202">
</recv>
<!-- 等待BYE请求 -->
<recv request="BYE">
<!-- 提取From标头 -->
<check_from uri="sip:user2@192.168.1.2" />
<!-- 提取To标头 -->
<check_to uri="sip:user3@192.168.1.3" />
</recv>
<!-- 发送200 OK响应 -->
<send>
<![CDATA[
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.1.2:5060;branch=z9hG4bK12347
From: sip:user2@192.168.1.2;tag=12345
To: sip:user3@192.168.1.3
Call-ID: 12345@192.168.1.2
CSeq: 3 BYE
Contact: sip:user2@192.168.1.2:5060
Content-Length: 0
]]>
</send>
</scenario>
```
如上所示,该脚本首先发送一个INVITE请求,等待100 Trying响应和200 OK响应。然后,发送一个REFER请求,将呼叫转移给URI为`<sip:user3@192.168.1.3>`的用户。最后,等待BYE请求和200 OK响应。在发送和接收消息时,可以使用`<check_*>`元素从SIP消息中提取信息,以便进行后续处理。
阅读全文