You are not logged in.

#1 2008-04-06 03:17:33

dlin
Member
From: Taipei,Taiwan
Registered: 2005-09-21
Posts: 265

netcfg2 enhanced with 'auto-ip'

Hi, everybody,  I've asked a question about netcfg2.
If I have a static IP on office, and a static IP on home.  Could netcfg2 auto detect it?  The answer is NO. The only way is use 'menu'.

I just wrote a script '/usr/bin/netcfg-auto-ip'.  So, the /etc/rc.conf could be

NETWORKS=(auto-ip office,home,dhcp)

Here is my netcfg-auto-ip, I wish it could be merged into netcfg2's source. Can anybody help me?

#! /bin/bash
# autoconnect one of static ip 
# usage: netcfg-auto-ip <network_profiles>
# eg. netcfg-auto-ip office,home

if [[ $# -ne 1 ]]; then
    err "Please supply multiple profile name separated by comma"
    exit 1
fi

networks=$(echo $1 | sed 's|,| |g')
for network in $networks ; do
    echo "Try: $network"
    if ! /usr/bin/netcfg2 -c $network ; then
        echo "$network already been started"
        exit 0
    fi
    gate=$(route -n | grep "^0.*eth0" | head -1 | awk '{print $2}')
    if ping -q -c1 -W1 $gate > /dev/null ; then
        exit 0
    fi
    echo "ping $network's gateway $gate failed"
    /usr/bin/netcfg2 -d $network
done
exit 1
# vim: set ts=2 noet:

Last edited by dlin (2008-04-06 03:18:57)


Running 4 ArchLinux including sh4twbox,server,notebook,desktop. my AUR packages

Offline

#2 2008-04-06 04:19:54

Phrodo_00
Member
From: Seattle, WA
Registered: 2006-04-09
Posts: 342
Website

Re: netcfg2 enhanced with 'auto-ip'

well, I haven't tried it (I don't use netcfg), but you probably should submit it to the flyspray.

Offline

#3 2008-04-07 23:21:51

dlin
Member
From: Taipei,Taiwan
Registered: 2005-09-21
Posts: 265

Re: netcfg2 enhanced with 'auto-ip'

Phrodo_00 wrote:

well, I haven't tried it (I don't use netcfg), but you probably should submit it to the flyspray.

I just added a task 10110
And, the updated script have put there.

Wish there are more people to vote my enhancement. Thanks.:)

I think this patch is useful for who need automatic switch static route/dhcp from different location.


Running 4 ArchLinux including sh4twbox,server,notebook,desktop. my AUR packages

Offline

Board footer

Powered by FluxBB