python - Comparing Network Traffic to Authorized List(s) via Domain Name
问题描述
I'm trying to parse through network traffic and compare the domain names in the traffic to a list of the most common websites. the intent is to print all the site names that are not on the list of common websites
with open('/Users/downloads/scripting_for_security/resources/top_100.txt') as f:
safeAdd = f.readlines(),
with open('/Users/downloads/scripting_for_security/resources/traffic_log.txt') as n:
netTraffic = n.readlines(),
domainTraffic = re.findall(r'\s(?:www.)?(\w+.com)', netTraffic)
for i in safeAdd:
for e in domainTraffic:
if i != e:
print(e)
getting a type error
TypeError Traceback (most recent call last) in 8 netTraffic = n.readlines(), 9 ---> 10 domainTraffic = re.findall(r'\s(?:www.)?(\w+.com)', netTraffic) 11 12
~/anaconda3/lib/python3.7/re.py in findall(pattern, string, flags) 221 222 Empty matches are included in the result.""" --> 223 return _compile(pattern, flags).findall(string) 224 225 def finditer(pattern, string, flags=0):
TypeError: expected string or bytes-like object
解决方案
netTraffic is a list as per https://docs.python.org/3/tutorial/inputoutput.html
findall expects a second argument of type string https://docs.python.org/3/library/re.html#re.findall
推荐阅读
- java - Firebase OnDataChange 未过渡到下一个活动
- node.js - 使用 putObject 时 S3 文件损坏
- math - 在垂直于线向量的 3D 空间中绘制一个点
- apache-spark - spark/sqoop 到 db2 的错误原因是:com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException
- angular - 使用 Firestore 管理多个 where 条件
- database - 如何自动检测区块链系统中的变化?
- javascript - 使用“前置”将 JQuery 代码转换为 Javascript 问题
- swift - 确定何时在 SwiftUI 中加载 Google Banner Ad
- flutter - 如何在 Flutter 中获取列表视图项目内单击按钮的索引?
- audio - 如何检查声音设备是否在 AutoHotkey 脚本中连接?