Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

changing localaddr

by vpitchai (Initiate)
on Nov 02, 2011 at 14:53 UTC ( #935414=perlquestion: print w/replies, xml ) Need Help??
vpitchai has asked for the wisdom of the Perl Monks concerning the following question:

Hi Experts; I am using the perl NET SNMP module to send SMNP version 2 traps, able to set the managers address (dest. ip address) with the hostname option without any issues but struggling to change the source ip address of the trap packet. If i set the localaddr to a different ip address (in my case, the ip address of the device), the script execution fails. What are options to set the source ip address? Thanks

Replies are listed 'Best First'.
Re: changing localaddr
by NetWallah (Canon) on Nov 02, 2011 at 15:40 UTC
Re: changing localaddr
by Khen1950fx (Canon) on Nov 02, 2011 at 17:30 UTC
    I was thinking along the same lines as NetWallah, but I discovered that -agentaddr isn't recognized by SNMPv2c. Maybe this is closer to what you need.
    #!/usr/bin/perl use strict; use warnings; use Net::SNMP::XS; use Net::SNMP qw(:ALL); my ( $session, $error ) = Net::SNMP->session( -hostname => '', -community => 'public', -localaddr => '', -port => SNMP_TRAP_PORT, -version => 'snmpv2c', -community => 'public', -debug => '0x02', -nonblocking => 0, ); if ( not defined $session ) { printf "ERROR: %s.\n", $error; exit 1; } my $result = $session->snmpv2_trap( -varbindlist => [ '', TIMETICKS, 600, '', OBJECT_IDENTIFIER, '', '', OCTET_STRING, 'Hub', '', OCTET_STRING, 'Closet Hub', ], ); if ( not defined $result ) { printf "ERROR: %s.\n", $session->error(); } else { printf "SNMPv2-Trap-PDU sent.\n"; }
Re: changing localaddr
by McA (Priest) on Nov 02, 2011 at 15:16 UTC

    probably a silly question, but the source address you specify is one which is bound to an interface on your sending machine?
    What is the error message?

    Best regards

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://935414]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2018-06-22 21:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.