#
ping_res = Popen("ping vk.com -n 1", stdout=PIPE, stderr=STDOUT)
text = ''
for line in ping_res.stdout.readlines():
text += line.decode('cp866')
vk = re.search(r'Среднее = (\d+) мсек', text)
if vk:
print(f"{vk.groups()[0]} мс")
import re
from subprocess import Popen, PIPE, STDOUT
ping_res = Popen("ping vk.com -n 1", stdout=PIPE, stderr=STDOUT)
lines = [i.decode('cp866') for i in ping_res.stdout.readlines()]
if bool(lines):
for line in lines:
if 'Среднее = ' in line:
vk = re.search(r'Среднее = (\d+) мсек', line)
print(f'{vk.groups()[0]} мс')
break
2022-07-06T11:10:08.853743+00:00 app[worker.1]: [Errno 1] Operation not permitted
2022-07-06T11:10:08.853764+00:00 app[worker.1]: Traceback (most recent call last):
2022-07-06T11:10:08.853765+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/vkbottle/dispatch/base.py", line 22, in route
2022-07-06T11:10:08.853766+00:00 app[worker.1]: await view.handle_event(event, ctx_api, self.state_dispenser)
2022-07-06T11:10:08.853767+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/vkbottle/dispatch/views/abc/message.py", line 73, in handle_event
2022-07-06T11:10:08.853767+00:00 app[worker.1]: handler_response = await handler.handle(message, **context_variables)
2022-07-06T11:10:08.853767+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/vkbottle/dispatch/handlers/from_func_handler.py", line 32, in handle
2022-07-06T11:10:08.853768+00:00 app[worker.1]: return await self.handler(event, **acceptable_context)
2022-07-06T11:10:08.853769+00:00 app[worker.1]: File "/app/main.py", line 333, in message_handler
2022-07-06T11:10:08.853769+00:00 app[worker.1]: vk_ping = str(ping('vk.com', verbose=False, count=3))
2022-07-06T11:10:08.853769+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/pythonping/__init__.py", line 79, in ping
2022-07-06T11:10:08.853769+00:00 app[worker.1]: comm = executor.Communicator(target, provider, timeout, interval, socket_options=options, verbose=verbose, output=out,
2022-07-06T11:10:08.853770+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/pythonping/executor.py", line 275, in __init__
2022-07-06T11:10:08.853771+00:00 app[worker.1]: self.socket = network.Socket(target, 'icmp', source=None, options=socket_options)
2022-07-06T11:10:08.853771+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/pythonping/network.py", line 33, in __init__
2022-07-06T11:10:08.853772+00:00 app[worker.1]: self.socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, self.protocol)
2022-07-06T11:10:08.853772+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/socket.py", line 232, in __init__
2022-07-06T11:10:08.853773+00:00 app[worker.1]: _socket.socket.__init__(self, family, type, proto, fileno)
2022-07-06T11:10:08.853773+00:00 app[worker.1]: PermissionError: [Errno 1] Operation not permitted
онлайн ping api- находятся множество вариантов.