如何将以字符表示的16进制数转换为机器码表示的16进制数

     在工作中需要做一个压力测试工具,在网络中发送指定内容的报文,报文内容是用 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 d<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />5 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

转换代码如下:

ExpandedBlockStart.gif ContractedBlock.gif      Private   Function sendFile() Function sendFile(ByVal filename As StringAs Byte()
InBlock.gif        
'读要发送的文件
InBlock.gif
        '将内容存于数组中byte中
InBlock.gif
        Dim s As [String'= "30 30 30 31 60 00 07 ff df ee 20 fc 20 20 20 20"
InBlock.gif
        Dim sp As [Char= " "
InBlock.gif
InBlock.gif        s 
= TextFromFile(filename)
InBlock.gif
InBlock.gif        
Dim r() As [String= s.Split(sp)
InBlock.gif        
Dim i As Integer
InBlock.gif        
Dim b As Byte() = New [Byte](r.Length) {}
InBlock.gif
InBlock.gif        
For i = 0 To b.Length - 1
InBlock.gif            
Try
InBlock.gif                b(i) 
= Byte.Parse(r(i), System.Globalization.NumberStyles.HexNumber)
InBlock.gif            
Catch e As Exception
InBlock.gif                
'
InBlock.gif
            End Try
InBlock.gif        
Next
InBlock.gif
InBlock.gif        sendFile 
= b
InBlock.gif
ExpandedBlockEnd.gif
End Function

None.gif

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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

转载于:https://www.cnblogs.com/Frances/archive/2006/02/24/337025.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值