sip调试 使用ngrep进行快速SIP包分析

sip调试

asterCC呼叫中心系统是一个基于SIP通信的系统,与传统的电话系统相比,语音的传送基于IP网络,因此学会如何调试VoIP通信是网络管理员们必须掌握的技能之一。这里我们会逐步介绍一些VoIP调试工具,希望能够帮助大家更好的设计、维护语音通信和呼叫中心系统。

什么是ngrep

ngrep是网络版的grep,用于从网络中过滤特定的信息,这里我们学习如何利用ngrep来调试SIP系统。

ngrep安装

yum install -y ngrep
对于sip 最常用的命令格式为
ngrep -dany -qWbyline "" port 5060
ngrep_any

ngrep sip调试

这个命令会输出到达该服务器5060端口的所有包,5060为sip的默认端口,这样所有sip包都会输出到屏幕
如果我们想看来自/发送到服务器astercc.org的包,命令为
ngrep -dany -qWbyline "" port 5060 and host astercc.org
ngrep_astercc

ngrep sip调试

我们也可以使用正则表达式来过滤特定的信息,例如我想看来自分机astercc-1000的包
ngrep -dany -qWbyline "astercc-1000" port 5060 and host astercc.org
使用ngrep过滤信息时可以使用正则表达式,例如只想看到SIP REGISTER包
ngrep -deth0 -qWbyline "^REGISTER" port 5060

其中 ^REGISTER 表示以REGISTER开头的包

我们也可以指定对某个网卡(eth0)进行查询 例如
ngrep -deth0 -qWbyline "astercc-1000" port 5060
 注意ngrep抓包的优先级高于iptables防火墙,如果ngrep中看到有包但是asterisk中看不到,则说明是iptables阻挡,需要检查iptables设置 [] [/]
使用ngrep我们也可以将输出保存到指定的文件,命令格式为
ngrep -W byline -d eth0 port 5060 -O capture_file
其他两个参数包括
  • -t : 以 年/月/日 的格式显示每个包的时间戳
  • -T: 以 +S.UUUUUU 的格式打印时间,用于表示两个包之间的时差

asterisk中的Sip调试

asterisk中查看sip包的方法为,登陆到linux系统,连接到asterisk控制台
asterisk -r
开启sip调试模式
sip set debug on
asterisk_sip_debug

asterisk sip调试

查看指定ip
sip set debug ip 76.68.146.197
关闭sip调试模式
sip set debug off
asterisk_sip_debug_off

asterisk sip调试

总结

ngrep命令使用方便,能够帮助我们快速定位问题,实际上ngrep不仅能够应用于sip协议,能够适用于任何明文传送的网络数据。

索克维尔旗下产品 · CXMind AI联络中心 · WCC全渠道联络中心