#!/usr/bin/python
#脚本抓取网络接口“以太网”的数据,如果有udp视频流的话,解析出provider_name。
# -*- coding: UTF-8 -*-
#scapy 2.4.3 python 3.7.3
from scapy.all import *
import time
import codecs
channel={
'233.110.201.20':'导视频道',
..........
'组播地址':'频道名称'
}
sdt_dest = '474011'#DST表匹配字节
def pack_callback(packet):
if len(packet)>1000:
out=packet['Raw'].load
result = codecs.encode(out, 'hex').decode()
srcip = packet['IP'].src
dstip = packet['IP'].dst
if (sdt_dest in result):
provider_name1=""
sdt_offset = result.find(sdt_dest)
#print(len(result),sdt_offset,sdt_offset+48)
if len(result)>sdt_offset+48:
provider_length=int(result[sdt_offset+48:sdt_offset+50],16)
if provider_length<20:
provider_start = sdt_offset+50
provider_end = provider_start+provider_length*2
provider_name = result[provider_start:provider_end]
for i in range(0,len(provider_name),2):
pn=chr(int(provider_name[i:i+2],16))
provider_name1=provider_name1+pn
service_length = int(result[provider_end:provider_end+2],16)
#service_name = result[sdt_offset+50+provider_length*2+2:sdt_offset+50+provider_length*2]
channel_name = channel.get(dstip,"未知")
print(time.strftime('%Y_%m_%d_%H:%M:%S',time.localtime()),"源地址:"+srcip+"---->目的地址:"+dstip+" 频道名称:"+channel_name+" 提供源:"+provider_name1)
print("===========================")
#print(sdt_offset,provider_length)
sniff(prn=pack_callback,iface='以太网',count=0,store=0)
用Scapy抓取网络包,如果有udp TS 视频流的话,解析出provider_name
最新推荐文章于 2021-06-29 09:00:00 发布