Skip to content

Instantly share code, notes, and snippets.

@zhreshold
Last active May 30, 2019 14:39
Show Gist options
  • Select an option

  • Save zhreshold/f4defab409cc0e6f6a0e75237f73ca99 to your computer and use it in GitHub Desktop.

Select an option

Save zhreshold/f4defab409cc0e6f6a0e75237f73ca99 to your computer and use it in GitHub Desktop.
Check OS/Python/Cpu Info and Network connections
import platform, subprocess, sys
import socket, time
try:
from urllib.request import urlopen
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from urllib2 import urlopen
print('----------Python Info----------')
print('Version :', platform.python_version())
print('Compiler :', platform.python_compiler())
print('Build :', platform.python_build())
print('Arch :', platform.architecture())
print('----------System Info----------')
print('Platform :', platform.platform())
print('system :', platform.system())
print('node :', platform.node())
print('release :', platform.release())
print('version :', platform.version())
print('machine :', platform.machine())
print('processor :', platform.processor())
print('----------Hardware Info----------')
if sys.platform.startswith('darwin'):
pipe = subprocess.Popen(('sysctl', '-a'), stdout=subprocess.PIPE)
output = pipe.communicate()[0]
for line in output.split('\n'):
if 'brand_string' in line or 'features' in line:
print(line.strip())
elif sys.platform.startswith('linux'):
subprocess.call(['lscpu'])
elif sys.platform.startswith('win32'):
subprocess.call(['wmic', 'cpu', 'get', 'name'])
print('----------Network Test----------')
timeout = 10
socket.setdefaulttimeout(timeout)
URLS = {
'Tutorial_site': 'https://zh.gluon.ai',
'FashionMNIST_EU': 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/',
'default_conda': 'https://repo.continuum.io/pkgs/free/',
'conda_tsinghua_mirror': 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/',
'default_pip': 'https://pypi.python.org/pypi/pip',
'pip_douban_mirror': 'https://pypi.douban.com/simple'
}
def connection_test(name, url):
urlinfo = urlparse(url)
start = time.time()
try:
ip = socket.gethostbyname(urlinfo.netloc)
except Exception as e:
print('Error resolving DNS for {}: {}, {}'.format(name, url, e))
return
dns_elapsed = time.time() - start
start = time.time()
try:
_ = urlopen(url, timeout=timeout)
except Exception as e:
print("Error open {}: {}, {}, DNS finished in {} sec.".format(name, url, e, dns_elapsed))
return
load_elapsed = time.time() - start
print("Timing for {}: {}, DNS: {:.4f} sec, LOAD: {:.4f} sec.".format(name, url, dns_elapsed, load_elapsed))
for name, url in URLS.items():
connection_test(name, url)
@az-pz
Copy link

az-pz commented May 30, 2019

Hey,
What's the license of this gist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment