python操作excel

import requests
import os
import time
import xlrd
import xlwt
import threading
import threadpool
import socket

class compare_app():
def init(self,path1,path2):
self.dict1={}
self.dict2={}
self.dict3={}
self.path1=path1
self.path2=path2

    def app_pipe(self):
            for root, dirs, files in os.walk(self.path1):
                    List1=files
                    print(List1) #当前路径下所有非目录子文件
                    for file in files:
                        data=xlrd.open_workbook('D:\\excel\\%s' %file,ragged_rows = True)
                        table=data.sheets()[0]
                       #print('----------------------------------------')
                        for row_index in range(table.nrows):
                            dstip = table.cell(rowx=row_index,colx=4).value
                            app_name=table.cell(rowx=row_index,colx=6).value
                            if dstip not in self.dict1 and dstip!="目的IP":
                               self.dict1[dstip]=app_name
                            else:
                               continue

            #for key,value in self.dict1.items():
            #        print( key+',',value)

            for root, dirs, files in os.walk(self.path2):
                    List2=files
                    print(List2) #当前路径下所有非目录子文件
                    for file in files:
                        data=xlrd.open_workbook('D:\\excel1\\%s' %file,ragged_rows = True)
                        table=data.sheets()[0]
                       #print('----------------------------------------')
                        for row_index in range(table.nrows):
                            dstip = table.cell(rowx=row_index,colx=4).value
                            app_name=table.cell(rowx=row_index,colx=6).value
                            if dstip  in self.dict1 and dstip!="目的IP":
                               self.dict2[dstip]=app_name
                            else:
                               continue
            #输出白名单误识别的目的IP和应用
            for key,value in self.dict2.items():
                    print( key+',',value)

if name == ‘main’:

pipei1=pipei(‘C:\Users\ThinkPad\Desktop\kl\URL_IP.xlsx’)

# pipei1.url_pipe()

#白名单应用目录:‘D:\excel1’
#误识别应用目录:‘D:\excel’
yuming1=compare_app(‘D:\excel’,‘D:\excel1’)
yuming1.app_pipe()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值