| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # network::modbus Brik | ||
| 5 | # | ||
| 6 | package Metabrik::Network::Modbus; | ||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use base qw(Metabrik::Client::Tcp); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | sub brik_properties { | ||
| 13 | return { | ||
| 14 | revision => '$Revision$', | ||
| 15 | tags => [ qw(unstable) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 17 | license => 'http://opensource.org/licenses/BSD-3-Clause', | ||
| 18 | commands => { | ||
| 19 | probe => [ qw(host port|OPTIONAL) ], | ||
| 20 | }, | ||
| 21 | }; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub probe { | ||
| 25 | my $self = shift; | ||
| 26 | my ($host, $port) = @_; | ||
| 27 | |||
| 28 | $host ||= $self->host; | ||
| 29 | $port ||= 502; | ||
| 30 | $self->brik_help_run_undef_arg('probe', $host) or return; | ||
| 31 | |||
| 32 | # XXX: gather nmap --script modbus-discovery -p 502 <IP> | ||
| 33 | |||
| 34 | # To port 502/TCP (from plcscan) | ||
| 35 | my $probe = | ||
| 36 | "\x00\x00\x00\x00\x00\x05\x00\x2b". | ||
| 37 | "\x0e\x01\x00"; | ||
| 38 | |||
| 39 | $self->host($host); | ||
| 40 | $self->port($port); | ||
| 41 | $self->connect or return; | ||
| 42 | $self->write($probe) or return; | ||
| 43 | my $response = $self->read or return; | ||
| 44 | $self->disconnect; | ||
| 45 | |||
| 46 | return $response; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ | ||