#! /usr/bin/perl -w use strict; my $DEBUG = 0; my ($if) = @ARGV; print STDERR "Detecting network for $if ..."; while () { chomp; my ($alias, $cmd, @arg) = split ' ', $_; my ($label) = ($alias); $label =~ s/.*[-:;]//; if ($cmd eq 'ping') { my ($from, $mask, $gw) = @arg; system('ifconfig', $if, '0.0.0.0', 'down'); system('ifconfig', $if, $from, 'netmask', $mask, 'up'); local $_ = qx(traceroute -n -r -i $if -I -w 3 -m 1 $gw 2>&1); print STDERR "\n",$_,"\n" if $DEBUG; system('ifconfig', $if, '0.0.0.0', 'down'); if (/\*|\!H/) { print STDERR " !$label"; next; } else { print STDERR " $label"; print STDOUT $alias; last; } } elsif ($cmd eq 'fallback') { print STDERR " $label"; print STDOUT $alias; last; } } print STDERR "\n"; exit;