How to configure the Comtrend’s HG532c ADSL router ARP table for (WOL) Wake On Lan from internet using expect

Several months ago I finally got the (WOL) Wake On Lan feature of my RTL8111/8168B NIC card working. The problem was that a new driver (other than the provided by Debian) and a special PCI configuration was needed.

The other problem I had to deal with was the ADSL Router (Comtrend HG532c, The one provided by the Spanish ISP Jazztel) configuration:

  • Open the required port: This was an easy one just opening the 7 a 9 port and forwarding them to the server we want to WOL from the internet
  • Make the router remember the server’s tuple MAC/IP address. That was easy too, but some manual work was needed as when router is restarted the ARP table is flushed.  🙁

In my current job I had to change recently some configuration and restart more than 600 IP phones. To perform such titanic task I created a quick and dirty script using expect. It worked like a charm and made me think about automatize the way I set the ARP table in my Comtrend HG532c ADSL router.

The scripts is very easy to understand. It just simulates a Telnet session with your router:

  1. Login and password
  2. Set the required MAC/IP tuple
  3. Displays the ARP table

Here you are:

#!/usr/bin/expect -f
set timeout 10
set env(TERM)

set router "router"  #your router's dns name or IP
set login "admin"    #your router's login. admin is the default
set password "admin" #your router's password. admin is the default
set ip "" #your server's IP address (not the dns name)
set mac "2f:1e:8a:84:2a:f9" #your server's MAC 

spawn telnet $router
expect "Login: "
send -- "$login\r"
expect "Password: "
send -- "$password\r"
expect "ATP>"
send "sh\r"
expect "# "
send "arp -s $ip $mac\r"
expect "# "
## check that all is right
send "arp -a\r"
expect "# "

The output must be similar to:

juan@mediacenter:~/bin$ ./
spawn telnet router
Connected to router.
Escape character is '^]'.
-----Welcome to ATP Cli------

Login: admin

BusyBox vv1.9.1 (2011-05-25 16:23:47 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

# arp -s 00:1e:8c:84:2a:f9
# arp -a
? ( at 2F:1E:8A:84:2A:F9 [ether] PERM on br0

As can be seen in the last line the router have set the ARP entry as permanent…. permanent till router next restart. 🙁 But at least every time this script is run the ARP is set automagically 🙂

The next thing to do is to put this script in a crontab job, /etc/rc.local, etc of one of your servers. This way every time it runs you will be sure that you can restart your server from the internet.

My decision was add a line in my server’s /etc/rc.local file like this:

#### Sets the MAC/IP tuple in ADSL router for WOL from internet
/path/to/ |mail -s "`hostname` MAC para el WOL" email@domain.tld

This has 2 added benefits:

  1. I will know when my server is started
  2. I will know that my router configuration is ready for wake on lan

The last step is have at least to ways to start your computer from the internet. Mine are:

  1. Online Wake-On-LAN web page.
  2. Wol Wake on Lan Wan for my Android phone.

I have created a github project: expect-update-arp-table-ADSL-router-for-wol (just in case other features can be added later) where you can download also the source code.



2 thoughts on “How to configure the Comtrend’s HG532c ADSL router ARP table for (WOL) Wake On Lan from internet using expect

  1. Thanks a lot for that one I’d been telneting to portforward my Router before and ATP just needs some extra steps. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

Información básica sobre protección de datos Ver más

  • Responsable: Juan Sierra Pons.
  • Finalidad:  Moderar los comentarios.
  • Legitimación:  Por consentimiento del interesado.
  • Destinatarios y encargados de tratamiento:  No se ceden o comunican datos a terceros para prestar este servicio. El Titular ha contratado los servicios de alojamiento web a ovh que actúa como encargado de tratamiento.
  • Derechos: Acceder, rectificar y suprimir los datos.
  • Información Adicional: Puede consultar la información detallada en la Política de Privacidad.


This site uses Akismet to reduce spam. Learn how your comment data is processed.