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

编程入门 行业动态 更新时间:2024-10-27 01:28:29
本文介绍了如何使用套接字获取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 + '\n' s.close()

我只收到一条消息,说星号版本,仅此而已.

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

我希望有人可以帮我这个忙.

I hope somebody could help me with this.

谢谢.

推荐答案

您在此处的代码格式有误. Asterisk AMI要求在命令之间使用\ r \ n终止.

You have malformed your code there. The Asterisk AMI requires \r\n 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 + '\r\n') data = s.recv(1024) print data + '\n' params = 'Action: status' s.send(params + '\r\n') data = s.recv(1024) print data + '\n' params = 'Action: Logoff' s.send(params + '\r\n') data = s.recv(1024) print data + '\n'

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

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

发布评论

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

>www.elefans.com

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