3 |
use strict; |
use strict; |
4 |
use IO::Socket::Multicast; |
use IO::Socket::Multicast; |
5 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
6 |
|
use Getopt::Long; |
7 |
|
|
8 |
use constant GROUP => '224.0.0.103'; |
my $GROUP = '224.0.0.103'; |
9 |
use constant PORT => '3235'; |
my $PORT = '3235'; |
10 |
|
|
11 |
my $debug = shift @ARGV; |
my $debug = 0; |
12 |
|
my $quiet = 1; |
13 |
|
my $verbose = 0; |
14 |
|
|
15 |
my $resend_search_delay = 3; |
my $resend_search_delay = 3; |
16 |
my $tftp_path = '/srv/tftp/'; |
my $tftp_path = '/srv/tftp/'; |
17 |
|
|
18 |
|
GetOptions( |
19 |
|
"port=i" => \$PORT, |
20 |
|
"group=s" => \$GROUP, |
21 |
|
"debug!" => \$debug, |
22 |
|
"quiet!" => \$quiet, |
23 |
|
"verbose!" => \$verbose, |
24 |
|
"search=i" => \$resend_search_delay, |
25 |
|
"tftp=s" => \$tftp_path, |
26 |
|
); |
27 |
|
|
28 |
|
$quiet = 0 if $verbose; |
29 |
|
|
30 |
# tab-delimited list of user id/passwd to try on ants |
# tab-delimited list of user id/passwd to try on ants |
31 |
my @try_accounts = ( "Administrator\t" ); |
my @try_accounts = ( "Administrator\t" ); |
32 |
|
|
44 |
warn "invalid $passwd_path entry: $_\n"; |
warn "invalid $passwd_path entry: $_\n"; |
45 |
} |
} |
46 |
} |
} |
47 |
print "found ", $#try_accounts, " accounts to try on password protected ants\n"; |
print "found ", $#try_accounts + 1, " accounts to try on password protected ants\n"; |
48 |
} |
} |
49 |
|
|
50 |
warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n"; |
warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n"; |
62 |
sub fw_build { |
sub fw_build { |
63 |
my $board_name = shift || return 0; |
my $board_name = shift || return 0; |
64 |
my $v = join('.', unpack('CCCC',fw($board_name,0x20,4)) ); |
my $v = join('.', unpack('CCCC',fw($board_name,0x20,4)) ); |
65 |
print "# fw_build $board_name $v\n"; |
print "# fw_build $board_name $v\n" unless $quiet; |
66 |
return $v; |
return $v; |
67 |
} |
} |
68 |
|
|
71 |
return -e "$tftp_path/$board"; |
return -e "$tftp_path/$board"; |
72 |
} |
} |
73 |
|
|
74 |
my $sock = IO::Socket::Multicast->new(LocalPort=>PORT,ReuseAddr=>1); |
my $sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1); |
75 |
$sock->mcast_add(GROUP) || die "Couldn't set group: $!\n"; |
$sock->mcast_add($GROUP) || die "Couldn't set group: $!\n"; |
76 |
$sock->mcast_ttl(1); |
$sock->mcast_ttl(1); |
77 |
|
|
78 |
sub ant2hash { |
sub ant2hash { |
94 |
map { $xor ^= ord($_) } split(//,$data); |
map { $xor ^= ord($_) } split(//,$data); |
95 |
$data .= sprintf('%02X', $xor); |
$data .= sprintf('%02X', $xor); |
96 |
|
|
97 |
$sock->mcast_send( $data, GROUP . ':' . PORT ); |
$sock->mcast_send( $data, "${GROUP}:${PORT}" ); |
98 |
if ($debug) { |
if ($debug) { |
99 |
warn ">> ", dump( $data ), $/; |
warn ">> ", dump( $data ), $/; |
100 |
} else { |
} elsif( ! $quiet ) { |
101 |
$data =~ s/\s+/ /gi; |
$data =~ s/\s+/ /gi; |
102 |
warn ">> ", substr($data,0,70), $/; |
warn ">> ", substr($data,0,70), $/; |
103 |
} |
} |
141 |
my $client_version = $h->{'MDAP-VERSION'}; |
my $client_version = $h->{'MDAP-VERSION'}; |
142 |
$mdap_ver = $client_version if ($client_version); |
$mdap_ver = $client_version if ($client_version); |
143 |
|
|
144 |
print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n"; |
print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet; |
145 |
|
|
146 |
warn dump($h),$/ if ($debug); |
warn dump($h),$/ if ($debug); |
147 |
|
|