linux - Create binary data using Ruby? -


I was peeling with Ruby sockets, so I ended up attempting to put an IP packet toggle, Try to make IP packet and make it a new one.

Now my problem is: If the packet is: 45 00 00 54 00 00 40 00 40 01 06 EF 7 F 00 00 01 7 F 00 00 01 , and it is clear It is hexadecimal, so I changed it to a decimal, then using binary data in a pane method, and pass it to the method of sending it, then Wireshark is much more than what I have created Strange, I'm doing something wrong, I know, but it does not understand:

Student, as I wrote @ data = "" @ data & lt; & Lt; @ Packet.to_s@socket. send (@ data.unpack (c *). To_s, @ address)

And there is another way to solve the whole thing, for example I Write directly to the data I want to send directly to socket buffer

Thanks in advance.

Starting with a hex part is a new idea, although I have a good idea to exploit it immediately Can not think of the way.

Anyway, on the problem .to_s , which will have the effect of creating a string with the decimal presentation of your number, and you will not take any further than bits any way

But by putting them back, then you open the string, which gives you an array of integers, which is the ascii value of the digit The decimal rep for the numeric value of the original hex string In Dattya, and then you .to_s that (which IO has done anyway, there is at least no fault), but it results in string as long as the uncreded string With printable representation of ascii numbers, you now light years with the original intentions.

  & gt; & Gt; T = 0x4500005400004000400106e07f0000017f000001 = & gt; 393920391770565046624940774228241397739864195073 & gt; & Gt; T.to_s = & gt; "393920391770565046624940774228241397739864195073" & gt; & Gt; T.to_s.unpack ('c *') = & gt; [51, 57, 51, 57, 50, 48, 51, 57, 49, 55, 55, 48, 53, 54, 53, 48, 52, 54, 54, 50, 52, 57, 52, 48, 55 , 55, 52, 50, 50, 56, 50, 52, 49, 51, 57, 55, 55, 51, 57, 56, 54, 52, 49, 57, 53, 48, 55, 51] and gt; ; T.to_s.unpack ('c *') To_s = & gt; "515751575048515749555548535453485254545052575248555555056505249515755555156565452495753485551" It is interesting in a way all the information is still there, type of.  

However, you need to create a binary string. Either just enter & lt; & Lt; Numbers:

  & gt; & Gt; S = ''; S & lt; & Lt; 1 & lt; & Lt; 2 = & gt; Use "001 \ 002"  

or array # pack:

  & gt; & Gt; [1,2] .pack 'c *' = & gt; "\ 001 \ 002"  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -