View previous topic :: View next topic |
Author |
Message |
afabco Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
Joined: 24 Feb 2004 Posts: 380
|
Posted: Wed Jul 30, 2008 11:29 pm Post subject: sending a hex string to a remote via netcat? |
|
|
Hey folks,
I've got some binary commands (which I'm representing as hex) that I need to send to a remote device (it's an embedded data collection device) and observe the reply.
It's easy to connect to it with netcat
Code: | nc -v 192.168.200.34 19000 |
and it sits there happy as a clam.
The hex string I need to send is something like:
Quote: | 05:64:10:D3:FD:00:00:00:E7:30:F5:C6:01:3C:02:07:1E:3C:03:07:1E:E7:59
|
But when I type this into my netcat window (with or without spaces , with or without the colons) netcat transmits it as ascii.
All the literature is happy to tell me how to capture a hexdump from the remote device, but not how to transmit binary/hex data to the remote device.
Is this an easy thing to do, or am I missing something?
thanks! _________________ Anyone who puts a small gloss on a fundamental technology, calls it proprietary, and then tries to keep others from building on it, is a thief.
-Tim O'Reilly |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Hu Administrator
![Administrator Administrator](/images/ranks/rank-admin.gif)
Joined: 06 Mar 2007 Posts: 23087
|
Posted: Thu Jul 31, 2008 3:12 am Post subject: |
|
|
Netcat will forward its input unmodified. Your best bet would be to find or make a tool that reads hexadecimal numbers and prints the corresponding bytes onto its standard output. Then do helper-cmd | nc 192.168.200.34 19000.
If you could write the data in base64 instead, then the coreutils program /usr/bin/base64 could transform your data into raw bytes for the wire. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
coolsnowmen Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/2048126856430177a506846.gif)
Joined: 30 Jun 2004 Posts: 1479 Location: No.VA
|
Posted: Thu Jul 31, 2008 7:40 pm Post subject: |
|
|
perhaps something like this (compile with g++ filename.c)
Code: | #include <cstdio>
#include <string>
//Written by Coolsnowmen for free
int hex2int(char &hex)
{
const static std::string key("0123456789abcdef");
return key.find( hex | 32 );
}
int main(int argnum,char ** argin)
{
if (argnum==2) {
int length=strlen(argin[1]);
if (length%2==0) {
for (int idx =0; idx<length; idx+=2)
printf("%c",hex2int(argin[1][idx])*16 + hex2int(argin[1][idx+1]));
return 0;
}
else {
fprintf(stderr,"non-even length string");
}
} else printf("1 argument expexted, of hexpairs, eg: %s 4a4f4e --> JON",argin[0]);
return 1;
} |
testing:
Code: | ./a.out 000102030405 | wc
0 0 6 |
_________________ emerge: there are no ebuilds to satisfy "moo" |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|