Results 1 to 7 of 7
  1.    #1  
    Hi all,

    I'm looking for a way to do some things based on network interfaces (in my case, eth0, but no reason we can't trigger on ppp0 too) coming online or going offline.

    /etc/network/if-up.d and /etc/network/if-down.d both exist, but in my limited testing, they don't seem to be used?

    Any help is appreciated.
    Last edited by knobbysideup; 02/22/2010 at 12:45 PM.
  2.    #2  
    *selfish bump*
  3. #3  
    Quote Originally Posted by knobbysideup View Post
    Hi all,

    I'm looking for a way to do some things based on network interfaces (in my case, eth0, but no reason we can't trigger on ppp0 too) coming online or going offline.

    /etc/network/if-up.d and /etc/network/if-down.d both exist, but in my limited testing, they don't seem to be used?

    Any help is appreciated.
    You need to patch one of the system files. I added 'run-parts /etc/network/if-up.d' line in the end of '/etc/pmnetconfig/if-up' file. Then when ever wifi is connected it executes the scripts in that directory. And the same can be done for the down part too.

    For the ppp0 connection the /etc/ppp/ip-up/down.d directories are used by default.
  4.    #4  
    Quote Originally Posted by sconix View Post
    You need to patch one of the system files. I added 'run-parts /etc/network/if-up.d' line in the end of '/etc/pmnetconfig/if-up' file. Then when ever wifi is connected it executes the scripts in that directory. And the same can be done for the down part too.

    For the ppp0 connection the /etc/ppp/ip-up/down.d directories are used by default.
    Thanks!
  5.    #5  
    For anybody interested, so far I have used this to automatically update my adblocking hosts file when I connect to my home network.

    put the following file somewhere as 'if-up' and make it executable. I like keeping it in my home directory, just so I keep all of my own modifications in one place. Add the appropriate lines to /etc/pmnetconfig/if-up (read comments) to run the script.

    You'll need to change MYSCRIPTS and TRUSTEDIP to match your file location and DHCP lease on your home network. I'll put a better solution for the network check in later.

    Code:
    #!/bin/sh
    
    # $HOME/customize/config/if-up
    #
    # For this to work, just add this to the bottom of /etc/pmnetconfig/if-up
    #
    #  MYSCRIPTS=/var/home/gspath/customize/config
    #  test -x $MYSCRIPTS/if-up && $MYSCRIPTS/if-up
    
    TRUSTEDIP='172.23.34.54'
    LOG='/usr/bin/logger -t ifup-post'
    WGET='/usr/bin/wget -q -O -'
    TR='/usr/bin/tr'
    CAT='/bin/cat'
    HOSTSURL='http://www.mvps.org/winhelp2002/hosts.txt'
    HOSTS='/etc/hosts'
    
    # We only want to do this stuff if on our own network
    # using a fixed IP address.  Find a way to do a hostname lookup
    # and use that to compare to gateway instead.
    if [ ${CMIPADDR} = "$TRUSTEDIP" ] && [ ${CMINTERFACE} = 'eth0' ]; then
    
    $LOG "Installing adblocking hosts file"
    $CAT <<EOF >$HOSTS
    127.0.0.1 localhost.localdomain localhost
    127.0.0.1 palm-webos-device
    
    EOF
    
    # Implement error catch and logging here eventually
    $WGET $HOSTSURL | $TR -d '\r' >> $HOSTS
    $LOG "Done installing adblocking hosts file"
    
    fi
  6. #6  
    I'd recommend adding some simple logic to parse the downloaded hosts file to ensure that it only has entries pointing to localhost (127.0.0.1) just in case the source for that is malicious or compromised and you end up download a hosts file includes entries for, say, bankofamerica.com pointing to a real (malicious, non-loopback) IP...
  7.    #7  
    Quote Originally Posted by vga4life View Post
    I'd recommend adding some simple logic to parse the downloaded hosts file to ensure that it only has entries pointing to localhost (127.0.0.1) just in case the source for that is malicious or compromised and you end up download a hosts file includes entries for, say, bankofamerica.com pointing to a real (malicious, non-loopback) IP...
    Thanks for the recommendation. I'll put that in! I also need to remove the redundant localhost stuff, but I was lazy when I wrote it. But at least I'm not requiring optware's perl installation :-)
    : (){:|:&};:

Tags for this Thread

Posting Permissions