01
特别说明:本文的服务器特指X86-PCServer硬件服务器
02
PART
X86-PCServer 网口信息获取
A
获取脚本
代码语言:javascript复制#!/usr/bin/python
#-*- coding: utf-8 -*-
#author: wangzhiguo
#date: 2020.01.29
import commands
class NetInterfaceInfo():
def __init__(self):
return
def get_net_interface_num(self):
status, output = commands.getstatusoutput("lspci | grep Eth | wc -l")
net_interface_num = int(output.strip())
return net_interface_num
def get_net_interface_1g_num(self):
net_interface_1g_num = self.get_net_interface_num - self.get_net_interface_10g_num()
return net_interface_1g_num
def get_net_interface_10g_num(self):
status, output = commands.getstatusoutput("lspci | grep -i eth | grep -E '10GbE|10-Gigabit' | wc -l")
net_interface_10g_num = int(output.strip())
return net_interface_10g_num
def get_all(self):
net_interface_num = self.get_net_interface_num()
net_interface_10g_num = self.get_net_interface_10g_num()
net_interface_1g_num = net_interface_num - net_interface_10g_num
return net_interface_num, net_interface_10g_num, net_interface_1g_num
def main():
temp = NetInterfaceInfo()
print(temp.get_all())
if __name__ == '__main__':
main()
B
获取方法概述
- 网口信息是通过lspci | grep -i eth来获取的
- 市面上主流的网口为1G和10G
- 接下来就是字符串的处理(过滤、分割、拼接)