赞
踩
- #!/usr/bin/python
- #coding=utf-8
- import dpkt
- import socket
- import optparse
-
- def printPcap(pcap):
- # 遍历[timestamp, packet]记录的数组
- for (ts, buf) in pcap:
- try:
- # 获取以太网部分数据
- eth = dpkt.ethernet.Ethernet(buf)
- # 获取IP层数据
- ip = eth.data
- # 把存储在inet_ntoa中的IP地址转换成一个字符串
- src = socket.inet_ntoa(ip.src)
- dst = socket.inet_ntoa(ip.dst)
- print '[+] 源地址: ' + src + ' --> 目标地址: ' + dst
- except:
- pass
-
- def main():
- parser = optparse.OptionParser('[*] Usage : ./pcapTest.py -f <file>')
- parser.add_option('-f',dest='fileName',type='string',help='specify target filename')
- (options,args) = parser.parse_args()
- fileName = options.fileName
-
- if fileName == None:
- print parser.usage
- exit(0)
- else:
- #f = open('geotest.pcap')
- f = open(fileName)
- pcap = dpkt.pcap.Reader(f)
- printPcap(pcap)
-
- if __name__ == '__main__':
- main()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。