执行1个perl文件时...... M遇到此问题
无法识别的字符\ x03;标记为< - HERE在PK< - HERE附近第3列mibwalk.pl第1行。
AnyBody对此有任何想法
Code--->
#!usr/bin/perl
use BER;
use SNMP_util;
use SNMP_Session;
$MIB1 = “sysLocation.0”;
$HOST = “192.168.1.150”;
($value) = &snmpget(“public\@$HOST”,”$MIB1”);
if($value) {
print “Results :$MIB1: :$value:\n”;
}
else { warn “No response from host :$HOST:\n”; }
答案 0 :(得分:1)
您的文件中似乎有一个字符\ x03。这是ASCII中的“文本结束”。它可能是您的.pl
文件本身或由其加载的内容。
如果您在文件开头看到^C
或^B
之类的内容,请将其删除。否则你可能不得不使用十六进制编辑器。
答案 1 :(得分:1)
您必须以十六进制格式发送字符串。 就我而言,使用NET :: SNMP模块是不可能的。
所以我修改了这个模块的源代码,使其成为可能。
我使用了以下版本的Net::SNMP
:
SNMP.pm,v 5.3 2005/10/20 14:17:01
Version v5.2.0
有关详细信息,请参阅本文的底部。
现在,您可以使用set_request()
的{{1}}函数和新的ASN.1类型HEX_STRING。
e.g:
Net::SNMP
<强>净:: SNMP ::消息强>
#! /usr/local/bin/perl
use strict;
use warnings;
use Net::SNMP;
my $OID_sysContact = '1.3.6.1.2.1.1.4.0';
my ($session, $error) = Net::SNMP->session(
-hostname => shift || 'localhost',
-community => shift || 'public',
);
my $rv = $session->set_request(-varbindlist => [ $OID_sysContact, HEX_STRING, 'FF0a1200' ],);
$session->close();
exit 0;
# ============================================================================
package Net::SNMP;
# $Id: SNMP.pm,v 5.3 2005/10/20 14:17:01 dtown Rel $
# [...]
# ============================================================================
use strict;
## Validate the version of Perl
BEGIN
{
die('Perl version 5.6.0 or greater is required') if ($] < 5.006);
}
## Version of the Net::SNMP module
our $VERSION = v5.2.0;
## Load our modules
use Net::SNMP::Dispatcher();
use Net::SNMP::PDU qw( :ALL );
use Net::SNMP::Security();
use Net::SNMP::Transport qw( :ports );
## Handle importing/exporting of symbols
use Exporter();
our @ISA = qw( Exporter );
our @EXPORT = qw(
INTEGER INTEGER32 OCTET_STRING OBJECT_IDENTIFIER IPADDRESS COUNTER
COUNTER32 GAUGE GAUGE32 UNSIGNED32 TIMETICKS OPAQUE COUNTER64 NOSUCHOBJECT
NOSUCHINSTANCE ENDOFMIBVIEW snmp_dispatcher HEX_STRING
);
our @EXPORT_OK = qw( snmp_event_loop oid_context_match );
our %EXPORT_TAGS = (
asn1 => [
qw( INTEGER INTEGER32 OCTET_STRING NULL OBJECT_IDENTIFIER SEQUENCE
IPADDRESS COUNTER COUNTER32 GAUGE GAUGE32 UNSIGNED32 TIMETICKS
OPAQUE COUNTER64 NOSUCHOBJECT NOSUCHINSTANCE ENDOFMIBVIEW
GET_REQUEST GET_NEXT_REQUEST GET_RESPONSE SET_REQUEST TRAP
GET_BULK_REQUEST INFORM_REQUEST SNMPV2_TRAP REPORT HEX_STRING )
],
# [...]
# no more changes in source code of Net::SNMP
# [...] only changes in description of Net::SNMP
# [documentation] ------------------------------------------------------------
=head1 EXPORTS
The Net::SNMP module uses the F<Exporter> module to export useful constants
and subroutines. These exportable symbols are defined below and follow the
rules and conventions of the F<Exporter> module (see L<Exporter>).
=over
=item Default
&snmp_dispatcher, INTEGER, INTEGER32, OCTET_STRING, OBJECT_IDENTIFIER,
IPADDRESS, COUNTER, COUNTER32, GAUGE, GAUGE32, UNSIGNED32, TIMETICKS,
OPAQUE, COUNTER64, NOSUCHOBJECT, NOSUCHINSTANCE, ENDOFMIBVIEW HEX_STRING
=item Exportable
&snmp_debug, &snmp_dispatcher, &snmp_type_ntop, &oid_base_match, &oid_lex_sort,
&ticks_to_time, INTEGER, INTEGER32, OCTET_STRING, NULL, OBJECT_IDENTIFIER,
SEQUENCE, IPADDRESS, COUNTER, COUNTER32, GAUGE, GAUGE32, UNSIGNED32, TIMETICKS,
OPAQUE, COUNTER64, NOSUCHOBJECT, NOSUCHINSTANCE, ENDOFMIBVIEW, GET_REQUEST,
GET_NEXT_REQUEST, GET_RESPONSE, SET_REQUEST, TRAP, GET_BULK_REQUEST,
INFORM_REQUEST, SNMPV2_TRAP, REPORT, DEBUG_ALL, DEBUG_NONE, DEBUG_MESSAGE,
DEBUG_TRANSPORT, DEBUG_DISPATCHER,DEBUG_PROCESSING, DEBUG_SECURITY, COLD_START,
WARM_START, LINK_DOWN, LINK_UP,AUTHENTICATION_FAILURE, EGP_NEIGHBOR_LOSS,
ENTERPRISE_SPECIFIC, SNMP_VERSION_1,SNMP_VERSION_2C, SNMP_VERSION_3, SNMP_PORT,
SNMP_TRAP_PORT, TRANSLATE_NONE,TRANSLATE_OCTET_STRING, TRANSLATE_NULL,
TRANSLATE_TIMETICKS, TRANSLATE_OPAQUE,TRANSLATE_NOSUCHOBJECT,
TRANSLATE_NOSUCHINSTANCE, TRANSLATE_ENDOFMIBVIEW, TRANSLATE_UNSIGNED,
TRANSLATE_ALL HEX_STRING
=item Tags
=over
=item :asn1
INTEGER, INTEGER32, OCTET_STRING, NULL, OBJECT_IDENTIFIER, SEQUENCE,
IPADDRESS, COUNTER, COUNTER32, GAUGE, GAUGE32, UNSIGNED32, TIMETICKS, OPAQUE,
COUNTER64, NOSUCHOBJECT, NOSUCHINSTANCE, ENDOFMIBVIEW, GET_REQUEST,
GET_NEXT_REQUEST, GET_RESPONSE, SET_REQUEST, TRAP, GET_BULK_REQUEST,
INFORM_REQUEST, SNMPV2_TRAP, REPORT, HEX_STRING
=item :debug
&snmp_debug, DEBUG_ALL, DEBUG_NONE, DEBUG_MESSAGE, DEBUG_TRANSPORT,
DEBUG_DISPATCHER, DEBUG_PROCESSING, DEBUG_SECURITY
=item :generictrap
COLD_START, WARM_START, LINK_DOWN, LINK_UP, AUTHENTICATION_FAILURE,
EGP_NEIGHBOR_LOSS, ENTERPRISE_SPECIFIC
=item :snmp
&snmp_debug, &snmp_dispatcher, &snmp_type_ntop, &oid_base_match, &oid_lex_sort,
&ticks_to_time, SNMP_VERSION_1, SNMP_VERSION_2C, SNMP_VERSION_3, SNMP_PORT,
SNMP_TRAP_PORT
=item :translate
TRANSLATE_NONE, TRANSLATE_OCTET_STRING, TRANSLATE_NULL, TRANSLATE_TIMETICKS,
TRANSLATE_OPAQUE, TRANSLATE_NOSUCHOBJECT, TRANSLATE_NOSUCHINSTANCE,
TRANSLATE_ENDOFMIBVIEW, TRANSLATE_UNSIGNED, TRANSLATE_ALL
=item :ALL
All of the above exportable items.
=back
=back
=head1 EXAMPLES
# [...]
# ============================================================================
1; # [end Net::SNMP]