Skip to content

Instantly share code, notes, and snippets.

@ckeyer
Created July 7, 2015 10:56
Show Gist options
  • Save ckeyer/76f433dcd29ac49b72d9 to your computer and use it in GitHub Desktop.
Save ckeyer/76f433dcd29ac49b72d9 to your computer and use it in GitHub Desktop.
获取主机信息
#!/usr/bin/python
import os
kernel_version = os.popen('''/bin/uname -a | awk \'{print $1,$3}\'''').read().strip('\n')
ip = os.popen('''/sbin/ifconfig | grep 'inet'|awk '{print $2}'|cut -d ":" -f 2''').read().strip('\n')
ipv6 = os.popen('''/sbin/ifconfig | grep 'inet6'|awk '{print $3}' ''').read().strip('\n')
memory = os.popen('''free -m | head -2''').read().strip('\n')
disk = os.popen('''df -hT''').read().strip('\n')
print "Kernel Version:",kernel_version
print "Local IP:",ip
print "Local IPv6:",ipv6
print "Local Memory:" + ('\n') + memory
print "Local Disk:" + ('\n') + disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment