如何使用 pyst 获取 SIP 对等列表?
How can I obtain a SIP peer list using pyst?
我想在我的 Python 应用程序中显示 Asterisk SIP peers。
我可以看到这样的列表正在执行:
[pbx:~] # asterisk -rx "sip show peers"
Name/username Host Dyn Forcerport Comedia ACL Port Status Description
212 (Unspecified) D No No 0 UNKNOWN
213 (Unspecified) D No No 0 UNKNOWN
217/217 169.0.5.17 D No No 5060 OK (29 ms)
....
在 Python 我使用 pyst 0.8
库:
import asterisk.manager
...
manager = asterisk.manager.Manager()
try:
manager.connect(host, port)
manager.login(usr, passwd)
r = manager.sippeers()
print('------- r ----')
pp.pprint(r)
print('-----------')
# ...
然后我漂亮地打印响应的一些字段。但我得到的只是:
------- r ----
Success
-----------
------ response -----
[ u'Response: Success\r\n',
u'ActionID: pbx-25332-00000001\r\n',
u'EventList: start\r\n',
u'Message: Peer status list will follow\r\n']
-----------
------ data -----
u''
-----------
------ headers -----
{ u'ActionID': u'pbx-25332-00000001',
u'EventList': u'start',
u'Message': u'Peer status list will follow',
u'Response': u'Success'}
-----------
----- multiheaders ------
{ u'ActionID': [u'pbx-25332-00000001'],
u'EventList': [u'start'],
u'Message': [u'Peer status list will follow'],
u'Response': [u'Success']}
-----------
如何使用 pyst
获取 SIP 对等点列表?
星号版本:
asterisk -r -vvvvv
Asterisk 11.17.1, Copyright (C) 1999 - 2013 Digium, Inc. and others. ...
sippeers()
只是发送 the SIPpeers
command directly. It doesn't do any listening for resulting events. According to documentation you get Peerlist
and PeerlistComplete
events after sending the command, so you will need to register a listener for the events. I haven't worked with pyst, so I'm not familiar with the structure of the events 的快捷方式,但希望这对您有所帮助。
import asterisk.manager
...
def evt_handler(evt, mgr):
print(f'Got event {evt.name}')
# do something with evt.data or evt.message
if evt.name == 'PeerlistComplete':
mgr.close()
manager = manager.Manager()
try:
manager.connect(host, port)
manager.login(usr, passwd)
manager.register_event('Peerlist', evt_handler)
manager.register_event('PeerlistComplete', evt_handler)
manager.sippeers()
我想在我的 Python 应用程序中显示 Asterisk SIP peers。
我可以看到这样的列表正在执行:
[pbx:~] # asterisk -rx "sip show peers"
Name/username Host Dyn Forcerport Comedia ACL Port Status Description
212 (Unspecified) D No No 0 UNKNOWN
213 (Unspecified) D No No 0 UNKNOWN
217/217 169.0.5.17 D No No 5060 OK (29 ms)
....
在 Python 我使用 pyst 0.8
库:
import asterisk.manager
...
manager = asterisk.manager.Manager()
try:
manager.connect(host, port)
manager.login(usr, passwd)
r = manager.sippeers()
print('------- r ----')
pp.pprint(r)
print('-----------')
# ...
然后我漂亮地打印响应的一些字段。但我得到的只是:
------- r ----
Success
-----------
------ response -----
[ u'Response: Success\r\n',
u'ActionID: pbx-25332-00000001\r\n',
u'EventList: start\r\n',
u'Message: Peer status list will follow\r\n']
-----------
------ data -----
u''
-----------
------ headers -----
{ u'ActionID': u'pbx-25332-00000001',
u'EventList': u'start',
u'Message': u'Peer status list will follow',
u'Response': u'Success'}
-----------
----- multiheaders ------
{ u'ActionID': [u'pbx-25332-00000001'],
u'EventList': [u'start'],
u'Message': [u'Peer status list will follow'],
u'Response': [u'Success']}
-----------
如何使用 pyst
获取 SIP 对等点列表?
星号版本:
asterisk -r -vvvvv
Asterisk 11.17.1, Copyright (C) 1999 - 2013 Digium, Inc. and others. ...
sippeers()
只是发送 the SIPpeers
command directly. It doesn't do any listening for resulting events. According to documentation you get Peerlist
and PeerlistComplete
events after sending the command, so you will need to register a listener for the events. I haven't worked with pyst, so I'm not familiar with the structure of the events 的快捷方式,但希望这对您有所帮助。
import asterisk.manager
...
def evt_handler(evt, mgr):
print(f'Got event {evt.name}')
# do something with evt.data or evt.message
if evt.name == 'PeerlistComplete':
mgr.close()
manager = manager.Manager()
try:
manager.connect(host, port)
manager.login(usr, passwd)
manager.register_event('Peerlist', evt_handler)
manager.register_event('PeerlistComplete', evt_handler)
manager.sippeers()