如何在delphi中使用winpcap的例子

如何在delphi中使用winpcap的例子,第1张

winpcap的几个函数相信你已经知册租唯道了,那么剩下的州培就自己看看学型滚学吧:

procedure recvThread(myconfig:pconfigini)stdcall

const

cStartPacket:array[0..63] of Byte=($01, $80, $c2, $00, $00, $03,

$ff, $ff, $ff, $ff, $ff, $ff,

$88, $8e, $01, $01, $00, $00,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5)

cuserPacket :array[0..63] of Byte = ($01, $80, $c2, $00, $00, $03,

$ff, $ff, $ff, $ff, $ff, $ff,

$88, $8e, $01, $00, $00, $ff,

$02, $01, $00, $ff, $01, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5)

cResponseMD5 :array[0..63] of Byte = ($01, $80, $c2, $00, $00, $03,

$ff, $ff, $ff, $ff, $ff, $ff,

$88, $8e, $01, $00, $00, $ff,

$02, $02, $00, $ff, $04, $10,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5)

cLogoffPacket :array[0..63] of Byte = ($01, $80, $c2, $00, $00, $03,

$ff, $ff, $ff, $ff, $ff, $ff,

$88, $8e, $01, $02, $00, $00,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5, $a5, $a5,

$a5, $a5, $a5, $a5)

var

outnetbyte,innetbyte:int64

StartPacket,userPacket,ResponseMD5,LogoffPacket:array[0..63] of Byte

szMd5Buffer: Md5Buffer

nLen: Integer

md5Ctx: MD5Context

md5Dig: MD5Digest

mmcount:string

pcap:ppcap

mac:TMacAddr//物理网卡地址

user:string

ErrStr:string

errbuf:array[0..PCAP_ERRBUF_SIZE] of Char

userlength,i:integer

buftoint : array[0..3] of byte

bufint:integer

headlen2:integer

pRecvBuf :array of Byte

pRecvHeaderBuf :ppcap_pkthdr

q_MD5Source:array[0..15] of byte

f:TextFile

textstring:string

begin

assignfile(f,'test.txt')

for i:=0 to 63 do

begin

StartPacket[i]:=cStartPacket[i]

userPacket[i]:=cuserPacket[i]

ResponseMD5[i]:=cResponseMD5[i]

LogoffPacket[i]:=cLogoffPacket[i]

end

buftoint[2]:=0

buftoint[3]:=0

try

pcap := pcap_open_live(PChar(myconfig^.ethname),

65535, PCAP_OPENFLAG_PROMISCUOUS, 1, errbuf)

except

showmessage('打开网卡失败')

isloop:=false

exit

end

// end

if pcap<>nil then

begin

mac:=Pcap_GetMacAddress (Pcap, ErrStr)

end

//填写mac地址

for i:=0 to 5 do

begin

StartPacket[i+6] := mac[i]

userPacket[i+6] := mac[i]

ResponseMD5[i+6] := mac[i]

LogoffPacket[i+6] := mac[i]

end

//填写账号

user:=myconfig^.username

userlength:=5+length(user)

userPacket[17]:=byte(userlength)

userPacket[21]:=byte(userlength)

for i:= 23 to length(user)+22 do

begin

userpacket[i] := Str_HexToInt(InttoHex( ord(user[i-22]) ,2))

end

//发送开始认证包

pcap_sendpacket(pcap, @StartPacket, SizeOf(StartPacket))

mmcount:=formatdatetime('ss',now())

while isloop=true do

begin

//

if (formatdatetime('ss',now()) <>mmcount) then

begin

try

PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 4, outnetbyte)

PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 5, innetbyte)

except

showmessage('子线程发送流量数据出错')

end

mmcount:=formatdatetime('ss',now())

end

//开始抓包

try

i:= pcap_next_ex(pcap, @pRecvHeaderBuf, @pRecvBuf)

except

showmessage('抓包函数出错')

end

if( i>0 ) then

begin

if (pRecvBuf[12] = $88) and (pRecvBuf[13] = $8e) then

begin

case precvbuf[18] of

$01:

begin

if (pRecvBuf[22] = $01) then //Request Identity

begin

//form1.Lab_login_state.Caption:='发送账号包'

try

pcap_sendpacket(pcap, @userpacket, SizeOf(userpacket))

except

showmessage('发送账号包出错')

end

end

else

begin

for i:=0 to 15 do

begin

q_MD5Source[i] := pRecvBuf[i + 24]

end

PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 0, 0)

szMd5Buffer[0] := $02

nLen := 1

CopyMemory(@szMd5Buffer[nLen], PChar(Trim(myconfig^.userpass)), Length(Trim(myconfig^.userpass)))// 用户密码

nLen := nLen + Length(Trim(myconfig^.userpass))

CopyMemory(@szMd5Buffer[nLen], @q_MD5Source, 16)// 服务器返回密钥

nLen := nLen + 16

for i:=0 to nlen-1 do

begin

textstring:=textstring+inttohex(szMd5Buffer[i],2)+' '

end

textstring:=textstring+#13#10

MD5Init(md5Ctx)

MD5Update(md5Ctx, @szMd5Buffer, nLen)

MD5Final(md5Ctx, md5Dig)

for i:= 24 to 39 do

begin

ResponseMD5[i] := md5dig[i-24]

textstring:=textstring+inttohex(md5dig[i-24],2)+' '

end

textstring:=textstring+#13#10

rewrite(f)

writeln(f,textstring)

responsemd5[17]:=byte(length(myconfig^.username)+22)

responsemd5[21]:=byte(length(myconfig^.username)+22)

for i:= 40 to length(user)+39 do

begin

ResponseMD5[i] := Str_HexToInt(InttoHex( ord(user[i-39]) ,2))

end

pcap_sendpacket(pcap, @ResponseMD5, SizeOf(ResponseMD5))

end

end

$03:

begin

PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 1, 0)

end

$04:

begin

PostMessage(myconfig^.formhandle, WM_THREAD_MSG, 3, 0)

isloop:=false

end

end

end

if (pRecvBuf[12] = $08) and (pRecvBuf[13] = $00) then

begin

if (pRecvBuf[23] = $06) then //tcp包

begin

try

buftoint[0]:= pRecvBuf[17]

buftoint[1]:= pRecvBuf[16]

Bufint := integer(buftoint)

except

showmessage('tcp字节转化错误')

end

headlen2:=20

case pRecvBuf[46] of

$50:headlen2:=20

$60:headlen2:=24

$70:headlen2:=28

$80:headlen2:=32

$90:headlen2:=36

$a0:headlen2:=40

$b0:headlen2:=44

$c0:headlen2:=48

end

//if totalbyte<3000000000 then totalbyte:=totalbyte+abuf^ - 20 -headlen2

if ((pRecvBuf[26] = $c0) or (pRecvBuf[26] = $ac) ) and ((pRecvBuf[30] = $c0) or (pRecvBuf[30] = $ac) ) then

begin

try

innetbyte:=innetbyte+ bufint - 20 -headlen2

except

showmessage('tcp计算出错in')

end

end

else

begin

try

outnetbyte:=outnetbyte+ bufint - 20 -headlen2

except

showmessage('tcp计算出错out')

end

end

//if (pRecvBuf[26] = $c0) and ( pRecvBuf[30] <>$c0 ) and (pRecvBuf[30] <>$ac) then outnetbyte:=outnetbyte+ abuf^ - 20 -headlen2

//if (pRecvBuf[30] = $c0) and ( pRecvBuf[26] <>$c0 ) and (pRecvBuf[26] <>$ac) then outnetbyte:=outnetbyte+ abuf^ - 20 -headlen2

//if (pRecvBuf[26] = $ac) and ( pRecvBuf[30] <>$c0 ) and (pRecvBuf[30] <>$ac) then outnetbyte:=outnetbyte+ abuf^ - 20 -headlen2

//if (pRecvBuf[30] = $ac) and ( pRecvBuf[26] <>$c0 ) and (pRecvBuf[26] <>$ac) then outnetbyte:=outnetbyte+ abuf^ - 20 -headlen2

end

if (pRecvBuf[23] = $11) then //udp包

begin

try

buftoint[0]:= pRecvBuf[17]

buftoint[1]:= pRecvBuf[16]

Bufint := integer(buftoint)

except

showmessage('udp字节转化错误')

end

if ((pRecvBuf[26] = $c0) or (pRecvBuf[26] = $ac) ) and ((pRecvBuf[30] = $c0) or (pRecvBuf[30] = $ac) ) then

begin

try

innetbyte:=innetbyte+ bufint - 28

except

showmessage('udp计算出错in')

end

end

else

begin

try

outnetbyte:=outnetbyte+ bufint - 28

except

showmessage('udp计算出错out')

end

end

end

end

end

end

pcap_sendpacket(pcap, @LogoffPacket, SizeOf(LogoffPacket))

end

转载

摘要:明拆许多关于视频的软件(如视频会议、可视电话等)开发都应用于视频捕获技术。微软为软件开发人员提供了一个专门用于视频捕获的VFW SDK,从而为在Windows系统中实现视频捕获提供了标准的接口,并大大降低了程序的开发难度。由于VFW SDK只有VC和VB版,没有Delphi版,因此需要在Delphi中一一声明DLL中的各个函数和变量。文中详细介绍了的步骤,同时给出了程序实例。

1 引言视频捕获与实时处理是目前图像处理系统中最关键的技术之一,能否准确捕获指定的视频图像,进而实现精确地数据分析与处理,关系到整个系统的成败。笔者在开发“公路安全线轧压检测系统”时就遇到此情况。该系统主要研究在公路关键地段,过往机动车辆是否瞬间轧压黄色安全线。因此车辆轧压安全线的一个主要原因是车辆超车或逆向行使而违反了上下行规则,这是造成交通事故的最主要、最直接的因素。本系统通过实时拍摄,抓取瞬间图像,并经过系统的分析和处理来及时准确地检测车辆行驶情况,从而驱动控制设备以作出相关处理。

显然,这个系统的关键之处是实时捕获视频图像。为此,采用微软公司推出的关于数字视频的一个软件包VFW。它能使应用程序通激厅枣过数字化设备从传统的模拟视频源得到数字化的视频剪辑。VFW的一个关键思想是播放时不需要专用硬件

。为了解决数字视频数据量大的问题,需要对数据进行压缩,而VFW引进了AVI的文件标准。该标准未规定如何对视频进行捕获、压缩及播放,仅规定视频和音频该如何存储在硬盘上及在AVI文件中交替存储视频帧和与之相匹配的音频数据。但VFW可使程序员通过发送消息或设置属性来捕获、播放和编辑视频剪辑。当用户在安装VFW时,安装程序会自动地安装配置视频所需要的组件,如设备驱动程序、视频压缩程序等。VFW主要由6个模块组成。具体如表1所列。

表1 VFW功能模块

模 块 功 能

AVICAP.DLL 包含执行视频捕获的函数,它给AVI文件的I/O处理和视频、音频设备驱动程序提供一个高级接口

MSVIDEO.DLL 包含一套特殊的DrawDib函数,用来处理屏幕上的视频 *** 作

MCIAVI.DRV 包括对VFW的MCI命令解释器的驱动程序

AVIFILE.DLL 包含由标准多媒体I/O(mmio)函数提供的更高的命令,用来访问.AVI文件

ICM 压缩管理器,用于管理的视频压缩/解压缩的编译码器(Codec)

ACM 音频压缩管理器,提供与ICM相似的服务,适用于波形音频2 视频捕获程序开发的基本步骤

2.1 使用伏谨AVICap窗口类

笔者使用的是AVICap窗口类来开发视频捕获程序。AVICap类支持实时视频流捕获和单帧捕获,并提供对视频源的控制。通常使用的MCI控件虽然也提供了数字视频服务。并为视频叠加提供了Overlay命令集等,但这些命令主要是基于文件的 *** 作,还不能满足实时地从视频缓存中提取数据的要求。对于使用没有视频叠加能力的捕获卡的PC机来说,用MCI提供的命令集是无法捕获视频流的。而AVICap窗口类在捕获视频方面具有一定的优势,它能直接访问视频缓冲区,而不需要生成中间文件,因而实时性很强,效率也很高。另外,它还可将数字视频捕获到一个文件中。

给一个你参考者租吧, 用的是 IDhttp控件

function TAutoCardFrom.LogOn(Name, Pass: string): Boolean

var

stream:TStringStream

begin

try

stream:=TStringStream.Create('emid='+Name+'&empassword='+Pass)

IdHttp1.HandleRedirects:=True

IdHttp1.Request.Referer:='http://88.88.8.88:81/Index.asp'

IdHttp1.Request.UserAgent:= 'Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1.NET CLR 2.0.50727InfoPath.1.NET CLR 3.0.4506.2152.NET CLR 3.5.30729)'

IdHttp1.Request.ContentType:='首腔兆application/x-www-form-urlencoded'

memo1.Lines.Text:=IdHttp1.Post('LogOn.asp'圆凳,stream) // 按钮触发

finally

stream.Free

end

end


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12278745.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存