[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