Translate (i)pppd hex output to ascii

Translate (i)pppd hex output to ascii

Post by Gerrit Hiddin » Thu, 29 Apr 1999 04:00:00



Hi,

some (all?) versions of (i)pppd print important messages only in hex
characters. These messages sometimes contain clues as to why setting up
a connection fails, so it is very important to be able to read these
messages. They look like this:

Apr 26 22:16:51 localhost pppd[888]: rcvd [PAP AuthNak id=0x0 49 6e 76 61 6c
69 64 20 4c 6f 67 69 6e 3a 20 55 6e 6b 6e 6f 77 6e 20 75 73 65 72 6e 61 6d
65 2e 0d 0a]

I've written a tiny program to translate it into ascii. It could have been
done with programs like 'hexdump', but figuring out how they work costs more
time than writing it.

My program is written as a filter, i.e. it accepts characters from stdin and
writes them to stdout. You can start it with: "cat | hex", and then copy
and paste the hexadecimal numbers into standard in. Compiling instructions
are in the source.

Here's the source (completely free of copyrights, rights and warranty):

#include <stdio.h>
#include <stdlib.h>

/* compile with cc hex.c -o hex
** Converts hex to ascii

*/

int conv(int a)
{
  if (a>'9')
  {
    a=a|32;
    return a-'a'+10;
  }
  else
    return a-'0';  

Quote:}

void main ()
{
  int a,b;

  while (!feof(stdin))
  {
    a=fgetc(stdin);
    while ((a==' ') || (a==13) || (a==10))
      a=fgetc(stdin);
    b=fgetc(stdin);

    printf("%c",conv(a)*16+conv(b));
  }

Quote:}

 
 
 

Translate (i)pppd hex output to ascii

Post by Rob Janss » Thu, 29 Apr 1999 04:00:00



>My program is written as a filter, i.e. it accepts characters from stdin and
>writes them to stdout. You can start it with: "cat | hex", and then copy
>and paste the hexadecimal numbers into standard in.

Why the cat?

Rob
--
+----------------------------------+--------------------------------------+


+----------------------------------+--------------------------------------+

 
 
 

Translate (i)pppd hex output to ascii

Post by Gerrit Hiddin » Thu, 29 Apr 1999 04:00:00




>>My program is written as a filter, i.e. it accepts characters from stdin and
>>writes them to stdout. You can start it with: "cat | hex", and then copy
>>and paste the hexadecimal numbers into standard in.
> Why the cat?

for sending keyboard input to stdin; you could also use "echo <whatever> |
hex" to start it. It is not designed to pipe the entire debug file through
it; if you do then normal text will become unreadable... it's not highly
sophisticated. Just select the hex text, and echo or cat it through the
proggy, and see what it means. It's one magnitude less laborously than
taking an ascii chart and manually decoding the hex output.

Grit

 
 
 

Translate (i)pppd hex output to ascii

Post by Robert Sande » Thu, 29 Apr 1999 04:00:00



Quote:> Hi,
> some (all?) versions of (i)pppd print important messages only in hex
> characters. These messages sometimes contain clues as to why setting up
> a connection fails, so it is very important to be able to read these
> messages. They look like this:
> Apr 26 22:16:51 localhost pppd[888]: rcvd [PAP AuthNak id=0x0 49 6e 76 61 6c
> 69 64 20 4c 6f 67 69 6e 3a 20 55 6e 6b 6e 6f 77 6e 20 75 73 65 72 6e 61 6d
> 65 2e 0d 0a]
> I've written a tiny program to translate it into ascii. It could have been
> done with programs like 'hexdump', but figuring out how they work costs more
> time than writing it.
> My program is written as a filter, i.e. it accepts characters from stdin and
> writes them to stdout. You can start it with: "cat | hex", and then copy
> and paste the hexadecimal numbers into standard in. Compiling instructions
> are in the source.

nice, thank You for the idea, I have "specialized" it to display the
hex-codes of isdnlog out of /var/log/daemon.log, that are coming after the
"HEX:" codeword:

/* compile with cc hex.c -o hex
** Converts hex to ascii


*/

int conv(int a) {
  if (a>'9') {
    a=a|32;
    return a-'a'+10;
  } else
    return a-'0';

Quote:}

void main () {
  int a,b;
  char code=0;

  while (!feof(stdin)) {
    a=fgetc(stdin);
    if (!code) {
      printf("%c", a);
      if (a=='H') {
        a=fgetc(stdin);
        printf("%c", a);
        if (a=='E') {
          a=fgetc(stdin);
          printf("%c", a);
          if (a=='X') {
            a=fgetc(stdin);
            printf("%c", a);
            if (a==':') {
              code = 1;
            }
          }
        }
      }
    } else {
      while (a==' ') {
        printf("%c", a);
        a=fgetc(stdin);
      }

      if ((a==13)||(a==10)) {
        printf("%c", a);
        code=0;
      } else {
        b=fgetc(stdin);

        printf("%c",conv(a)*16+conv(b));
      }
    }
  }

Quote:}

--
Robert Sander   "Is it Friday yet?"

    pgp available there
 
 
 

Translate (i)pppd hex output to ascii

Post by Erik Corr » Thu, 29 Apr 1999 04:00:00



Quote:> Hi,
> some (all?) versions of (i)pppd print important messages only in hex
> characters. These messages sometimes contain clues as to why setting up
> a connection fails, so it is very important to be able to read these
> messages. They look like this:
> Apr 26 22:16:51 localhost pppd[888]: rcvd [PAP AuthNak id=0x0 49 6e 76 61 6c
> 69 64 20 4c 6f 67 69 6e 3a 20 55 6e 6b 6e 6f 77 6e 20 75 73 65 72 6e 61 6d
> 65 2e 0d 0a]
> I've written a tiny program to translate it into ascii. It could have been

If you can program in C it would be an even better solution if you
would look at the ipppd source code and find out why it is using
hex in the first place.  It must be a bug.  My version here doesn't
do it, it looks like the following:

Apr 11 08:28:37 ec ipppd[26225]: rcvd [0][PAP AuthNak id=0xamsg="Invalid Login"]

which is much more useful.  The bug must have crept in since I
got my version (can't remember unfortunately).

--
We believe that God is on our side. --Netscape chief executive James Barksdale
--

 
 
 

Translate (i)pppd hex output to ascii

Post by Rob Janss » Thu, 29 Apr 1999 04:00:00





>>>My program is written as a filter, i.e. it accepts characters from stdin and
>>>writes them to stdout. You can start it with: "cat | hex", and then copy
>>>and paste the hexadecimal numbers into standard in.
>> Why the cat?
>for sending keyboard input to stdin; you could also use "echo <whatever> |
>hex" to start it. It is not designed to pipe the entire debug file through
>it; if you do then normal text will become unreadable... it's not highly
>sophisticated.

"cat |" is nearly a no-op.

Rob
--
+----------------------------------+--------------------------------------+


+----------------------------------+--------------------------------------+

 
 
 

Translate (i)pppd hex output to ascii

Post by Rob Janss » Fri, 30 Apr 1999 04:00:00



>If you can program in C it would be an even better solution if you
>would look at the ipppd source code and find out why it is using
>hex in the first place.  It must be a bug.  My version here doesn't
>do it, it looks like the following:
>Apr 11 08:28:37 ec ipppd[26225]: rcvd [0][PAP AuthNak id=0xamsg="Invalid Login"]

                                                       ^^^^^^^^^

The omission of a space before 'msg' is also a long standing bug that
has been copied from pppd.

Of course copying pppd already is a bug.

Rob
--
+----------------------------------+--------------------------------------+


+----------------------------------+--------------------------------------+

 
 
 

Translate (i)pppd hex output to ascii

Post by Gerrit Hiddin » Fri, 30 Apr 1999 04:00:00



Quote:>>>>My program is written as a filter, i.e. it accepts characters from stdin and
>>>>writes them to stdout. You can start it with: "cat | hex", and then copy
>>>>and paste the hexadecimal numbers into standard in.
>>> Why the cat?
>>for sending keyboard input to stdin; you could also use "echo <whatever> |
>>hex" to start it. It is not designed to pipe the entire debug file through
>>it; if you do then normal text will become unreadable... it's not highly
>>sophisticated.
> "cat |" is nearly a no-op.

er

you could also write just "./hex", can't you ;)

I hadn't thought of that before. I know, I must be very ashamed.
Sometimes things are even more simple than they seem.

I'll go read the Beginners' Guide into Linux now.

Grit

 
 
 

Translate (i)pppd hex output to ascii

Post by Rob Janss » Fri, 30 Apr 1999 04:00:00




>>>>>My program is written as a filter, i.e. it accepts characters from stdin and
>>>>>writes them to stdout. You can start it with: "cat | hex", and then copy
>>>>>and paste the hexadecimal numbers into standard in.
>>>> Why the cat?
>>>for sending keyboard input to stdin; you could also use "echo <whatever> |
>>>hex" to start it. It is not designed to pipe the entire debug file through
>>>it; if you do then normal text will become unreadable... it's not highly
>>>sophisticated.
>> "cat |" is nearly a no-op.
>er
>you could also write just "./hex", can't you ;)
>I hadn't thought of that before. I know, I must be very ashamed.
>Sometimes things are even more simple than they seem.
>I'll go read the Beginners' Guide into Linux now.

Years ago there used to be a "Useless use of cat"-of-the-week award
in the comp.os.unix group.  I don't know if it still exists.

It was awarded to that week's person who posted some shell script (usually
to have it debugged by newsgroup readers) that contained things
like:

cat filename | sed -e "s/x/y"

But also "cat |", of course.

Rob
--
+----------------------------------+--------------------------------------+


+----------------------------------+--------------------------------------+

 
 
 

Translate (i)pppd hex output to ascii

Post by Kjoe » Wed, 12 May 1999 04:00:00


Quote:

> >>>>>My program is written as a filter, i.e. it accepts characters from
stdin and
> >>>>>writes them to stdout. You can start it with: "cat | hex", and then
copy
> >>>>>and paste the hexadecimal numbers into standard in.

> >>>> Why the cat?

> >>>for sending keyboard input to stdin; you could also use "echo
<whatever> |
> >>>hex" to start it. It is not designed to pipe the entire debug file
through
> >>>it; if you do then normal text will become unreadable... it's not
highly
> >>>sophisticated.

> >> "cat |" is nearly a no-op.

> >er

> >you could also write just "./hex", can't you ;)

> >I hadn't thought of that before. I know, I must be very ashamed.
> >Sometimes things are even more simple than they seem.

> >I'll go read the Beginners' Guide into Linux now.

> Years ago there used to be a "Useless use of cat"-of-the-week award
> in the comp.os.unix group.  I don't know if it still exists.

> It was awarded to that week's person who posted some shell script (usually
> to have it debugged by newsgroup readers) that contained things
> like:

> cat filename | sed -e "s/x/y"

> But also "cat |", of course.

> Rob
> --

i'm sure somebody finds cat useful for something
 
 
 

Translate (i)pppd hex output to ascii

Post by Kjoe » Wed, 12 May 1999 04:00:00


Quote:

> >>>>>My program is written as a filter, i.e. it accepts characters from
stdin and
> >>>>>writes them to stdout. You can start it with: "cat | hex", and then
copy
> >>>>>and paste the hexadecimal numbers into standard in.

> >>>> Why the cat?

> >>>for sending keyboard input to stdin; you could also use "echo
<whatever> |
> >>>hex" to start it. It is not designed to pipe the entire debug file
through
> >>>it; if you do then normal text will become unreadable... it's not
highly
> >>>sophisticated.

> >> "cat |" is nearly a no-op.

> >er

> >you could also write just "./hex", can't you ;)

> >I hadn't thought of that before. I know, I must be very ashamed.
> >Sometimes things are even more simple than they seem.

> >I'll go read the Beginners' Guide into Linux now.

> Years ago there used to be a "Useless use of cat"-of-the-week award
> in the comp.os.unix group.  I don't know if it still exists.

> It was awarded to that week's person who posted some shell script (usually
> to have it debugged by newsgroup readers) that contained things
> like:

> cat filename | sed -e "s/x/y"

> But also "cat |", of course.

> Rob
> --

i'm sure somebody finds cat useful for something
 
 
 

Translate (i)pppd hex output to ascii

Post by Andre Bec » Fri, 14 May 1999 04:00:00



> i'm sure somebody finds cat useful for something

Of course. You can as well make a list of "unexpected" uses of cat,
especially on Linux. My favourites:

cat /boot/mbr.b > /dev/hda           # Write 444byte MBR to disk
cat /dev/zero > /dev/hda             # Wipe out a disk (DELETE)

Or copy a floppy:

cat /dev/fd0 > floppy.img
superformat /dev/fd0                    # after insert of new disk ;)
cat floppy.img > /dev/fd0

Or create a compressed image of a hard disk for later cloning:

mount /dev/hdaX /mnt
cat /dev/zero > /mnt/bigwaste.tmp
rm /mnt/bigwaste.tmp
umount /mnt
gzip -9c < /dev/hda > /store/hda.hdimg.gz

In the last example, cat is used quite creative, isn't it ?  ;->

--

 "the big bang: the ultimate hero of low frequency;
  the divine intergalactical bassdrum" -- Yello, "solar driftwood"

+-o-+--------------------------------------------------------+-o-+
| o |               \\\- Brain Inside -///                   | o |
| o |                   ^^^^^^^^^^^^^^                       | o |
| o | Andre' Beck (ABPSoft)   AB10-RIPE    Xlink PoP Dresden | o |
+-o-+--------------------------------------------------------+-o-+

 
 
 

1. Outputting to a log file and translating output

I want to output a command to a specific log and somehow with in that log
for a certain event that happens with in it send a email out. This is what I
have I was wondering since I am new to bash what areas I need to address.
Also I would like to be able to either
A.     Run this script against a ip address or a ip list or list of commands
. And if List how would list look like just a normal list of ips separated
by returns?
This is part of my script I have so far. Keep in mind I am new to the bash
process.

#!/bin/bash
#This is script to run snmpget on remote adtrans ip list and sends it to
/var/log/snmp.log
#Developed by Shane
#Network Surveillance
#ipaddr=/tmp/ip.list this is a attempt to do a ip list instead of inputing
specific ips in script
date
echo "Waiting 60 seconds before next command takes place..."
#snmpwalk -v 1 -c public 172.18.60.246:161 1.3.6.1.4.1.664.2.444.1.1.1.1.1 >
/var/log/snmp.log
echo `snmpwalk -v 1 -c public "$ipaddr"`
exit 0

B. Once the output hits the log it will look like this
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.4 = INTEGER: 2
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.5 = INTEGER: 2
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.6 = INTEGER: 2
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.7 = INTEGER: 3
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.8 = INTEGER: 3
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.9 = INTEGER: 4
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.10 = INTEGER: 4
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.11 = INTEGER: 5
SNMPv2-SMI::enterprises.664.2.444.1.1.3.1.6.12 = INTEGER: 1

This is the output to the log I would like to send a email if lets say in
instance integer changes from 1 .

Any pointers to the certain things I need to learn or examples similiar or
anything to help me in this would be greatly appreciated. Thanks in advanced

2. Cheque printing

3. Translating characters to hex (e.g., space===%20h)

4. Distributed processing server s/w?

5. dhcpsvc (how to translate HEX pool to decimal ip)

6. tcp-relay performance question

7. Is there a way to translate a hex number to decimal using awk or nawk.

8. test: argument expected error

9. ascii to hex

10. Ascii to Hex in bash

11. Converting Hex Dump to ASCII

12. How to HEX DUMP an ascii file?

13. How to find Hex values in ascii UNIX files