CentOS & Ubuntu 查看网口信息脚本
来源:互联网 发布:java开源文件管理系统 编辑:程序博客网 时间:2024/06/04 18:43
注:自动屏蔽掉了回环口 lo
# coding=utf-8import psutilimport platformimport osdef get_net_info(): if 'centos' in platform.platform(): path = '/etc/sysconfig/network-scripts' info = psutil.net_if_addrs() data = {} for i in info: if i != 'lo': abs_path = '{}/ifcfg-{}'.format(path, i) stor = {} with open(abs_path, 'r') as f: for line in f: if 'IPADDR' in line: a = line.split('=')[1].strip() stor['IP'] = a if 'NETMASK' in line: a = line.split('=')[1].strip() stor['NETMASK'] = a if 'TYPE' in line: a = line.split('=')[1].strip() stor['TYPE'] = a if 'ONBOOT' in line: a = line.split('=')[1].strip() if a == 'yes': stor['STATUS'] = 1 else: stor['STATUS'] = 0 data[i] = stor return data if 'Ubuntu' in platform.platform(): info = psutil.net_if_addrs() path = '/etc/network/interfaces' data = {} for i in info: if i != 'lo': stor = {} with open(path, 'r') as f: a = f.read() lis = a.split('\n\n') for block in lis: if i in block: result = block.split('\n') for line in result: if 'address' in line: a = line.split(' ')[1].strip() stor['IP'] = a if 'netmask' in line: a = line.split(' ')[1].strip() stor['NETMASK'] = a if block.startswith('#'): stor['STATUS'] = 0 else: stor['STATUS'] = 1 config_info = os.popen('ifconfig') for line in config_info: if 'Link encap' in line and i in line: stor['TYPE'] = line.split('Link encap:')[1].split('HWaddr')[0].strip() data[i] = stor return data
阅读全文
0 0
- CentOS & Ubuntu 查看网口信息脚本
- 通过Wireshark查看Gb口信令
- 网口信号灯的作用
- CentOS & Ubuntu 改变网口IP脚本
- CentOS & Ubuntu 开关网口脚本
- ubuntu、centos查看修改主机名
- 盘口信息语言的深度解读
- 解析开收盘盘口信息
- 通过GUID读取COM口信息
- Liunx怎么查看centos以及ubuntu版本
- 盘口的秘密---盘口信息深度功略!
- 查看Linux 是Red Hat,CentOS还是ubuntu
- 查看Ubuntu计算机硬件基本信息的一个脚本文件
- CentOS Nginx的一个初始化脚本(用于启动、停止、查看状态)
- linux查看网口流量的脚本
- CentOS查看系统信息-CentOS查看命令
- CentOS查看系统信息-CentOS查看命令
- Linux系统查看系统版本号的方法总结(包括Ubuntu,Redhat,CentOS)
- 解决Incorrect integer value: for column id; at row 1
- Noip2017那两天的经历
- 不同架构的字节顺序释疑
- android 输入法软件盘弹出遮挡原界面
- svn 中的switch的使用
- CentOS & Ubuntu 查看网口信息脚本
- 文章标题
- algo_ADMM(alternating direction multiplier method)
- 安装后启动虚拟机,提示虚拟机版本不兼容,无法使用的解决办法
- Spark
- Caffe系列之命令行解析
- Linux中iptables设置详细
- Linux内核死机调试方法总结
- MySql基本操作