小软在努力

希望明天会更好

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
    在工作中需要做一个压力测试工具,在网络中发送指定内容的报文,报文内容是用Sniffer工具捕捉下来的。内容如下所示:

交易码0001发送924.txt
======================

30 30 30 31 60 00 07 ff df ee 20 fc 20 20 20 20

20 20 20 20 20 20 20 20 20 30 31 37 30 32 35 30

30 30 30 30 30 20 20 20 20 20 20 20 20 20 20 20

20 20 20 20 20 d5 c5 b5 c0 c5 e6 20 20 30 30 30

30 30 30 30 30 30 30 30 30 30 30 30 30 31 37 30

30 30 30 30 31 20 20 20 20 20 20 20 20 20 20 20

20 20 20 20 20 31 30 30 30 31 32 30 30 35 30 39

……

30 30 30 31就是0001

转换代码如下:

    Private Function sendFile(ByVal filename As StringAs Byte()
        
'读要发送的文件
        '将内容存于数组中byte中
        Dim s As [String'= "30 30 30 31 60 00 07 ff df ee 20 fc 20 20 20 20"
        Dim sp As [Char= " "

        s 
= TextFromFile(filename)

        
Dim r() As [String= s.Split(sp)
        
Dim i As Integer
        
Dim b As Byte() = New [Byte](r.Length) {}

        
For i = 0 To b.Length - 1
            
Try
                b(i) 
= Byte.Parse(r(i), System.Globalization.NumberStyles.HexNumber)
            
Catch e As Exception
                
'
            End Try
        
Next

        sendFile 
= b

End Function

工具做好后自己用Sniffer捕捉了一下,和原来的东西一样,呵呵。

posted on 2006-02-24 16:08  小软  阅读(1739)  评论(0编辑  收藏  举报