如何使用套接字获取 Asterisk 服务器的状态

编程入门 行业动态 更新时间:2024-10-26 23:25:06
本文介绍了如何使用套接字获取 Asterisk 服务器的状态 - Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 python 套接字获取 Asterisk 服务器的状态,但没有任何反应.

I'm trying to get the status of an Asterisk Server using a python socket but nothing happens.

这是我的代码:

import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST = '192.168.1.105' PORT = 5038 s.connect((HOST, PORT)) params = """Action: login Events: off Username: admin Secret: mypass Action: status Action: Logoff """ s.send(params) data = s.recv(1024) print data + ' ' s.close()

我只收到一条消息,上面写着 Asterisk 版本,仅此而已.

I just get a message saying Asterisk Version and nothing more.

我希望有人能帮我解决这个问题.

I hope somebody could help me with this.

提前致谢.

推荐答案

您的代码格式不正确.Asterisk AMI 需要在命令之间 终止.

You have malformed your code there. The Asterisk AMI requires termination between commands.

您需要在单独的数据包中发送每个命令:

You need to send each command in a separate packet:

params = """Action: login Events: off Username: admin Secret: mypass""" s.send(params + ' ') data = s.recv(1024) print data + ' ' params = 'Action: status' s.send(params + ' ') data = s.recv(1024) print data + ' ' params = 'Action: Logoff' s.send(params + ' ') data = s.recv(1024) print data + ' '

这应该可以解决问题.显然,您还想为它创建一个函数或其他任何东西,但这将使它起作用.

That should do the trick. Obviously you'll want to also make a function for it or whatever, but that will make it work.

始终将 AMI 命令分开!

Always separate AMI commands out!

更多推荐

如何使用套接字获取 Asterisk 服务器的状态

本文发布于:2023-08-07 03:49:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316806.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   状态   服务器   Asterisk

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!