python 例外与异常mac地址
2015-11-20 16:42
519 查看
。
[root@pc0003 MySQL-python-1.2.5]# yum install MySQL-python #!/usr/bin/python #coding=utf-8 ''' 依赖MySQLdb python库 依赖host="192.168.****.***",user="****",passwd="****",db="****" 依赖glpi.switch1119表 ''' import os import MySQLdb os.mkdir(r'tmp') filedir='./tmp/6.exception.mac-wlan.onboard.mac.error.list.csv' MacFile=open(filedir,'w') MacFile.write("exception.mac\nMAC地址,用户,设备型号,批准来源\n") print("正在联络数据库") conn=MySQLdb.connect(host="192.168.****.****",user="****",passwd="****",db="****") cur=conn.cursor() select=cur.execute("use ****;") print("正在获取wlan与glpi不匹配的 exception.mac") select=cur.execute("select mac from switch1119 where UPPER(switch1119.mac) not in(select upper(glpi_items_devicenetworkcards.mac) from glpi_items_devicenetworkcards,glpi_devicenetworkcards where glpi_items_devicenetworkcards.devicenetworkcards_id = glpi_devicenetworkcards.id);") info = cur.fetchmany(select) for i in info: MacFile.write(str(i)[2:-3]+",unknow\n") print("正在获取glpi里Ethernet-Onboard的MAC 存在于 wlan中的MAC") MacFile.write("\n\nonboard.mac?\nMAC地址,用户,设备型号,批准来源\n") select=cur.execute("select mac from switch1119 where UPPER(switch1119.mac) in (select upper(glpi_items_devicenetworkcards.mac) from glpi_items_devicenetworkcards,glpi_devicenetworkcards where glpi_items_devicenetworkcards.devicenetworkcards_id = glpi_devicenetworkcards.id and glpi_devicenetworkcards.designation='Ethernet-Onboard');") info = cur.fetchmany(select) for i in info: MacFile.write(str(i)[2:-3]+",unknow\n") cur.close() conn.commit() conn.close() MacFile.close() print('文件保存路径:'+filedir) [root@pc0003 glpi_switch_ocs]# cat ./tmp/6.exception.mac-wlan.onboard.mac.error.list.csv exception.mac MAC地址,用户,设备型号,批准来源 20:7C:8F:76:****,unknow 34:DE:1A:1B:****,unknow onboard.mac? MAC地址,用户,设备型号,批准来源 C8:F7:33:15:****,unknow C8:F7:33:18:****,unknow
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法