package main import ( "fmt" "github.com/StackExchange/wmi" ) type Storage struct { Name string FileSystem string Total uint64 Free uint64 } type storageInfo struct { Name string Size uint64 FreeSpace uint64 FileSystem string } func get
在linux上想获取文件的元信息,我们需要使用系统调用lstat或者stat. 在golang的os包里已经把stat封装成了Stat函数,使用它比使用syscall要方便不少. 这是os.Stat的原型: func Stat(name string) (FileInfo, error) Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError. 返
内存信息 / meminfo 返回dict #!/usr/bin/env python def memory_stat(): mem = {} f = open("/proc/meminfo") lines = f.readlines() f.close() for line in lines: if len(line) < 2: continue name = line.split(':')[0] var = line.split(':'
我们可以使用 python 代码通过调用 ifconfig 命令来获取 Linux 主机的 IP 相关信息,包括:网卡名称.MAC地址.IP地址等. 第一种实现方式: #!/usr/bin/python #encoding: utf-8 from subprocess import Popen, PIPE def getIfconfig(): p = Popen(['ifconfig'], stdout = PIPE) data = p.stdout.read().split('\n\n') r