Web 51 - ip2hex.pl, mac2hex.pl

html2db.pl  software.html  RTL8019AS Packet Driver 1

Scripts mac2hex.pl and ip2hex.pl convert MAC and IP addresses into a format suitable for Web 51 development system. They were inspired by similar GPL'ed scripts by Bruce Lightner. Six forms of output are possible, selectable by command-line options.

  1. -define selects C-like definitions of constants:
    #define STATIC_MAC_MSB 00000h	/* MAC address  */
  2. -bat selects format usable in batch files:
    set MAC=
  3. -equ selects A51 assembly include file format:
    MAC_MSB equ      00000h  ; MAC address
  4. -equ together with -binutils select mcs51-as include file format:
    .equ    MAC_MSB, 0x0000  ; MAC address
  5. -binutils alone selects mcs51-as-like definitions of data constants:
            .word   0x0000   ; Ethernet address
  6. If no -define/bat/equ/binutils is specified, A51 format for data constant definitions is used:
            dw      00000h   ; Ethernet address
  7. -v prints the entered MAC/IP address to standard error, as a debugging check.

MAC or IP address can be specified from the command line, contained in a file, or piped from another program. Output goes to standard output and can be redirected with usual syntax of the command interpreter, e.g.

 perl mac2hex.pl 00:00:E8:EE:10:33 > mac.inc

If the input is in a file, two specifications are possible:

  1. Enter the file name on the command line after the @ prefix:
    perl ip2hex.pl @file
  2. Redirect standard input, and terminate the command line with -. Under DOS32, several ways of redirecting standard input are possible, e.g.
    type ip | perl ip2hex.pl -
    perl ip2hex.pl - < ip

If no arguments are given, a simple help is printed out:

 usage: ip2hex.pl [-v] [-define] [-bat] [-equ] [-binutils] x.y.z.w
        ip2hex.pl [-v] [-define] [-bat] [-equ] [-binutils] @file
        ip2hex.pl [-v] [-define] [-bat] [-equ] [-binutils] - < file

 usage: mac2hex.pl [-v] [-define] [-bat] [-equ] [-binutils] ddd.ddd.ddd.ddd.ddd.ddd
        mac2hex.pl [-v] [-define] [-bat] [-equ] [-binutils] hh:hh:hh:hh:hh:hh
        mac2hex.pl [-v] [-define] [-bat] [-equ] [-binutils] @file
        mac2hex.pl [-v] [-define] [-bat] [-equ] [-binutils] - < file

mac2hex.pl - Format of input (MAC address)

Two MAC address formats are allowed. First, dot-separated decimal numbers:

Second, colon-separated hexadecimal numbers:


Any lines that begin with # are assumed to be comments. A commented input file may look like:

 # default Web 51 Ethernet address

ip2hex.pl - Format of input (IP address)

IP address is given as four dot-separated decimal numbers. Up to 4 entries may be specified, with the following meaning:

  1. IP Address of Web 51. Mandatory.
  2. IP Netmask. If unspecified, default of is used.
  3. IP Gateway. If unspecified, default of means no gateway.
  4. IP Partner. Specifies the IP address with which a connection is established, if there are incoming data from the serial line. Not all applications use this function. If unspecified, default of turns off active establishing of connection

A specification of IP address can look like this:

Any lines that begin with #. are assumed to be comments. A commented input file may look like this:

 # default Web 51 IP address
 #IP MASK GW POINT (target partner IP)

Sponzored by LPhard Ltd. Graphics by GIMP Created by EasyPad

(c)Copyright 2000 - 2002, HW server & Radek Benedikt
Web51@HW.cz, Web51.HW.cz
html2db.pl  Obsah  RTL8019AS Packet Driver 1