网站制作毕业设计wordpress导入模板
web/
2025/9/29 3:42:33/
文章来源:
网站制作毕业设计,wordpress导入模板,北京免费网站建设,网络营销方案策划书上篇文章搭建了一个UDP多播程序的基础#xff0c;所谓基础#xff0c;就是看着它#xff0c;我可以写简单的多播程序了#xff0c;可以在这个基础上面开始工作了。会多播了#xff0c;多播的内容从哪里来#xff0c;播出什么内容呢#xff1f;呵呵#xff0c;有个设备所谓基础就是看着它我可以写简单的多播程序了可以在这个基础上面开始工作了。会多播了多播的内容从哪里来播出什么内容呢呵呵有个设备没有通讯协议用wireshark抓包分析协议编程实现之这就是此次多播的任务。启动wireshark抓取数据包导出为文本文件三五十兆的文件ultraedit搜索观察眼睛都看直了有设备通讯数据还有上网浏览的数据有QQ的数据有MSN的数据还有些不知所以的数据看了个晕头转向感觉设备的通讯数据的结构有点规律有门儿。咱是程序员有啥问题看看能不能编程解决呢上python提取数据这样子会让分析数据方便一些还能用提取的数据做测试。看看wireshark导出数据格式每个数据段都是“NO.”开头的接下来的一行是源IP和目标IP后面还有一段“Data:”标识的数据段有规律我用python提取这些数据没问题。如果规律不明显我就没辙了。Python程序要完成的功能l提取指定ip地址的数据把数据包部分保存到一个文件A中这就方便观察设备发送的数据定义出相关的结构l然后从文件A中提取出数据部分保存为文件B我在VC程序中读取这个文件B尝试解析这些数据如果能够成功解析我的工作就基本完成了看程序。#codinggb18030import fileinput# 本程序的bug因为导出二进制数据时字符串匹配以0000 为# 开始标志这与wireshark导出文件的第一个包的时间0.000000相# 同,所以第一个你要手工把0.000000改为0.000001。# 本程序就是为了导出数据加以分析不必为了修正上面的bug绕半天## 在介绍本程序功能之前先了解一下wireshark文件的格式。# wireshark导出文件格式No.是开始标志开始标志的# 下一行是ip地址和协议信息接下来是它协议分析的一些输出# 最后是Data。##No. Time Source Destination Protocol Info# 16 58.5 192.168.0.66 234.5.6.7 UDP Source port: 1024 Destination port: synchronet-db## 这中间是wireshark分析的输出###Data (40 bytes)##0000 e9 24 00 00 ff ff 01 00 02 00 00 00 d2 04 00 00 .$..............#0010 14 00 00 00 42 03 01 00 00 00 00 00 05 00 00 00 ....B...........#0020 02 00 00 00 33 00 00 00 ....3...##-------------------------------------------------------# 本程序的功能是读取wireshark的导出文件过滤出指定ip的数据# 1. Print_Data_Text导出从一个No.到下一个No.之间的内容# 2. Print_Data_bin 导出Data 部分的内容格式如下#e9 24 00 00 ff ff 01 00 02 00 00 00 d2 04 00 00#14 00 00 00 42 03 01 00 00 00 00 00 05 00 00 00#02 00 00 00 33 00 00 00#----#e9 24 00 00 ff ff 01 00 02 00 00 00 d2 04 00 00#14 00 00 00 42 03 01 00 00 00 00 00 05 00 00 00#02 00 00 00 33 00 00 00#在两个数据包之间插入了一样----,# 3. Print_IP_Line 仅导出包含ip的行就是No.下面的那行#-------------------------------------------------------# 如何设置导出数据的条件# 导出数据的条件# and字段的内容必须全部满足# or字段的内容至少满足一个# and 字段和 or 字段都满足# 如果and字段不存在则认为条件满足# 如果or字段不存在则认为条件满足#No. Time Source Destination Protocol Info#14 9.949685 192.168.0.66 234.5.6.7 UDP Source port: onehome-remote Destination port: synchronet-db# 举例# 导出满足下面条件的数据# No.下面一行的数据包含234.5.6.7和UDP# 并且包含192.168.0.202和192.168.0.22之一# cond []# cond.append({# and:[234.5.6.7, UDP],# or:[192.168.0.202, 192.168.0.22],# })##-------------------------------------------------------# 导出满足条件的数据, 为了在导出的文件中能看到数据是从# 源文件的那个地方来的导出的数据可以带有行号信息行号# 添加在每行数据的前面# fileName: 原始数据文件名称# saveto : 导出数据保存文件名称# cond : 数据需要满足的条件# with_ln_number : 导出数据时是否带行号# 只有带行号的数据才能被Print_Data_bin函数使用def Print_Data_Text(fileName, saveto, cond, with_ln_numberTrue):f1 open(saveto, w)ln []myfile fileinput.input(fileName)for x in myfile:ln.append(x)start_flag 0start_ln 0end_ln 0end_flag 0find_count 0print for i in range(0,len(ln)):if ln[i].find(No.) 0 and start_flag 1:start_flag 0if ln[i].find(No.) 0 and start_flag 0:if Check_Expr(ln[i1], cond)True:start_ln istart_flag 1find_count find_count 1msg msg (/b/b/b/b/b/b/b%02d)%(find_count)print msg,if start_flag 1:msg if with_ln_number True:msg (%08d:/t%s)%(i1,ln[i])else:msg (%s)%(ln[i])f1.write(msg)f1.close()# 导出数据包中的Data字段的内容# 通过查找 0000 作为开始标志# 查找Data:作为结束标志def Print_Data_bin(fileName, saveto, data_start, data_end, with_ln_numberTrue):f1 open(saveto, w)ln []myfile fileinput.input(fileName)for x in myfile:ln.append(x)start_flag 0start_ln 0end_ln 0end_flag 0find_count 0print for i in range(0,len(ln)):if start_flag 0 and Check_Expr(ln[i], data_start)True:start_flag 1msg (%s/n)%(ln[i][16:63])f1.write(----/n)if start_flag 1 and Check_Expr(ln[i], data_end)True:start_flag 0if start_flag 1:msg if with_ln_number True:msg (%s/n)%(ln[i][16:63])else:msg (%s/n)%(ln[i][6:53])f1.write(msg)# if i 100:# breakf1.close()def Check_Expr(ln, expr):expr_flag Falsefor x in expr:and_flag Trueor_flag Falseif and in x:for y in x[and]:if ln.find(y) -1:and_flag Falsebreakif or in x:for y in x[or]:if ln.find(y) ! -1:or_flag Truebreakelse:or_flag Trueif and_flag True and or_flag True:expr_flag Truebreakreturn expr_flag## 为了方便查看数据网来只# 打印带有IP地址的那行数据#def Print_IP_Line(fileName, saveto,cond):f1 open(saveto, w)ln []myfile fileinput.input(fileName)for x in myfile:ln.append(x)start_flag 0start_ln 0end_ln 0end_flag 0find_count 0print ,for i in range(0,len(ln)):if ln[i].find(No.) 0:if Check_Expr(ln[i1], cond) True:start_ln i1start_flag 1find_count find_count 1msg msg (/b/b/b/b/b/b/b/b%02d)%(find_count)print msg,if start_flag 1:msg msg (%08d:/t%s)%(start_ln1,ln[start_ln])f1.write(msg)start_flag 0f1.close()if __name__ __main__:src_data_file c://ws.txttxt_data_file_11 d://RE_11.txtbin_data_file_11 d://bin_11.txttxt_data_file_66 d://RE_66.txtbin_data_file_66 d://bin_66.txt## 导出数据的条件# and字段的内容必须全部满足# or字段的内容至少满足一个# and 字段和 or 字段都满足# 如果and字段不存在则认为条件满足# 如果or字段不存在则认为条件满足# 举例#No. Time Source Destination Protocol Info#14 9.949685 192.168.0.202 234.5.6.7 UDP Source port: onehome-remote Destination port: synchronet-db# 导出满足下面条件的数据# No.下面一行的数据包含234.5.6.7和UDP并且并且包含192.168.0.202和192.168.0.22之一# cond []# cond.append({# and:[234.5.6.7, UDP],# or:[192.168.0.202, 192.168.0.22],# })#cond []cond.append({and:[234.5.6.7, UDP],or:[192.168.0.202, 192.168.0.22],})getdata_start []getdata_start.append({and:[0000 ],})getdata_end []getdata_end.append({and:[Data: ],})# print getdata_start# Print_IP_Line(c://RE.txt,cond)filter_data_11 []filter_data_11.append({and:[192.168.0.22, 234.5.6.7, UDP],})filter_data_66 []filter_data_66.append({and:[192.168.0.202, 234.5.6.7, UDP],})Print_Data_Text(src_data_file, txt_data_file_11, filter_data_11)Print_Data_bin(txt_data_file_11, bin_data_file_11,getdata_start, getdata_end)Print_Data_Text(src_data_file, txt_data_file_66, filter_data_66)Print_Data_bin(txt_data_file_66, bin_data_file_66,getdata_start, getdata_end)Print_Data_bin(src_data_file, d://ttxx1.txt,getdata_start, getdata_end, 0)Print_IP_Line(src_data_file,d://ttxx2.txt, cond)
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/83675.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!