/[mdap]/mdap-server.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /mdap-server.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations)
Sun Apr 22 14:41:18 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1784 byte(s)
use exact dump of protocol packets
1 #!/usr/bin/perl
2
3 use strict;
4 use IO::Socket::Multicast;
5 use Data::Dump qw/dump/;
6
7 use constant GROUP => '224.0.0.103';
8 use constant PORT => '3235';
9
10 my $local_port = 1000;
11
12 my $resend_search_delay = 3;
13
14 my $sock = IO::Socket::Multicast->new(LocalPort=>PORT,ReuseAddr=>1);
15 $sock->mcast_add(GROUP) || die "Couldn't set group: $!\n";
16 $sock->mcast_ttl(1);
17
18 sub ant2hash {
19 my $data = shift;
20 my $hash;
21 map {
22 if ( m/:/ ) {
23 my ($n,$v) = split(/:/,$_,2);
24 $hash->{$n} = $v;
25 }
26 } split(/[\n\r]/, $data);
27 return $hash;
28 }
29
30 sub mdap_send {
31 my $data = shift;
32 warn ">> $data\n>>----------\n";
33 $sock->mcast_send( "${data}", GROUP . ':' . PORT );
34 }
35
36 local $SIG{ALRM} = sub {
37 mdap_send("ANT-SEARCH MDAP/1.1\r\n46");
38 alarm( $resend_search_delay );
39 };
40
41 alarm( $resend_search_delay );
42
43 while (1) {
44 my $data;
45 next unless $sock->recv($data,1024);
46
47 if ( $data =~ m#^(REPLY-\S+)\s(MDAP/\d+\.\d+)# ) {
48
49 my ($type,$proto) = ($1,$2);
50
51 my $h = ant2hash($data);
52
53 print "# $type $proto ", dump( $h ), $/;
54
55 if ($type eq 'REPLY-ANT-SEARCH') {
56 mdap_send("INFO MDAP/1.2\r\nSEQ-NR:1\r\nTO-ANT:0644JTHJ4\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n22");
57 } elsif ($type eq 'REPLY-INFO') {
58 if (
59 $h->{'_BUILD'} eq '6.1.7.2' &&
60 $h->{'_BUILDNAME'} eq 'ZZO9AA6.172' &&
61 $h->{'_BUILDVARIANT'} eq 'AA' &&
62 1
63 ) {
64 mdap_send("EXEC-CLI MDAP/1.2\r\nCLI-CMD:software upgrade\r\nSEQ-NR:1\r\nTO-ANT:0644JTHJ4\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n1F");
65 } else {
66 print "skipped updating ",
67 }
68 } elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) {
69 mdap_send("EXEC-CLI MDAP/1.2\r\nSEQ-NR:2\r\nTO-ANT:0644JTHJ4\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n5F");
70 } else {
71 print "!! reply ignored\n";
72 }
73
74 } else {
75 print $data, "\n", "-" x 30, "\n";
76 }
77 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26