Skip to content

Instantly share code, notes, and snippets.

@kt351b
Forked from sboily/rtpengine_calls.py
Last active February 17, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kt351b/44e7e82fa4f700b62f79a42217b6cda7 to your computer and use it in GitHub Desktop.
Save kt351b/44e7e82fa4f700b62f79a42217b6cda7 to your computer and use it in GitHub Desktop.
List call from rtpengine python asyncio
#!/usr/bin/env python3
import aiohttp
import asyncio
import bencodepy
import random
async def main():
headers = {'content-type': 'application/x-rtpengine-ng'}
async with aiohttp.ClientSession(headers=headers) as session:
cookie = f"0_{random.randint(1000, 9999)}_1"
bdata = bencodepy.encode({'command': 'list'}).decode('utf-8')
data = f"{cookie} {bdata}"
async with session.post('http://xxx.xxx.xxx.xxx:xxx/ng', data=data) as response:
result = await response.text()
result = result.split(" ", 1)
result_bytes = result[1].encode('utf-8')
r = bencodepy.decode(result_bytes)
print(r)
print("Calls: " + str(len(r[b'calls'])))
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment