比较两个文本文件并计算出现次数 [英] Comparing two text files and counting number of occurrences

查看:169
本文介绍了比较两个文本文件并计算出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试写一篇关于使用通用接入点名称的危险的博客文章.

I'm trying to write a blog post about the dangers of having a common access point name.

因此,我做了一些努力,以获取访问点名称的列表,然后从Renderlab下载了1000个最常见的访问点名称(存在彩虹表)的列表.

So I did some wardriving to get a list of access point names, and I downloaded a list of the 1000 most common access point names (which there exists rainbow tables for) from Renderlab.

但是我该如何比较这两个文本文件,以查看我收集的有多少个可访问彩虹表攻击的访问点名称?

But how can I compare those two text files, to see how many of my collected access point names that are open to attacks from rainbow tables?

文本文件的构建方式如下:

The text files are build like this:

collected.txt:

collected.txt:

linksys
internet
hotspot

大多数常用的接入点名称被称为 SSID.txt:

Most common access point names are called SSID.txt:

default
NETGEAR
Wireless
WLAN
Belkin54g

因此脚本应该对行进行排序,比较并显示在SSID.txt中找到了来自collected.txt的行的次数.

So the script should sort the lines, compare them and show how many times the lines from collected.txt are found in SSID.txt ..

这有意义吗?任何帮助将不胜感激:)

Does that make any sense? Any help would be grateful :)

推荐答案

如果您不介意使用python脚本:

If you don't mind using python script:

file1=open('collected.txt', 'r')            # open file 1 for reading
with open('SSID.txt', 'r') as content_file: # ready file 2
    SSID = content_file.read()

found={}                                    # summary of found names
for line in file1:
    if line in SSID:
        if line not in found:
            found[line]=1
        else:
            found[line]+=1
for i in found:
    print found[i], i                       # print out list and no. of occurencies

...它可以在包含以下文件的目录中运行-collected.txt和SSID.txt-它会返回如下所示的列表:

...it can be run in the dir containing these files - collected.txt and SSID.txt - it will return a list looking like this:

5 NETGEAR
3 default
(...)

脚本逐行读取文件1并将其与整个文件2进行比较.可以轻松地对其进行修改以从命令提示符处获取文件名.

Script reads file 1 line-by line and compares it to the whole file 2. It can be easily modified to take file names from command prompt.

这篇关于比较两个文本文件并计算出现次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆