Skip to content

Instantly share code, notes, and snippets.

@mmyjona
Created October 19, 2012 10:03
Show Gist options
  • Save mmyjona/3917268 to your computer and use it in GitHub Desktop.
Save mmyjona/3917268 to your computer and use it in GitHub Desktop.
ping with python popen
##mmyjona2012-10-19 18:02:38
from subprocess import *
import subprocess
import re
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
output = Popen(["ping", "-n", "3", "baidu.com"],startupinfo=startupinfo, stdout=PIPE).communicate()[0]
regex = re.compile(r"from\s(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b).*bytes=(\d*).*time=(\d*).*TTL=(\d*)")
r = regex.findall(output)
print r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment