Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Cisco SNMP CDP Poll

by Anonymous Monk
on Jun 23, 2006 at 12:20 UTC ( #557156=note: print w/ replies, xml ) Need Help??


in reply to Re: Cisco SNMP CDP Poll
in thread Cisco SNMP CDP Poll

some devices do not insert a 0x infront of hex ip The result is that the ip could not be translated. Maybe this could solve the problem?!

################################################## sub Convert_IP { my($ip , $result , $crap); my($hex1 , $hex2 , $hex3 , $hex4); my($oct1 , $oct2 , $oct3 , $oct4); my($hex_ip) = $_[0] ; #========================================================= +================== # Manche Geräte schicken die hexadezimale IP-Adresse # ohne führendes "0X" welches eine Hexadezimale Zahl # kennzeichnet # Für den Fall das keine "0x" mitgeschickt wird unter # Umständen die $hex_ip als ASCII Zeichen intepretiert. # Diese Schleife wandelt das ASCII Zeichen in eine # Hexadezimale Zahl um # und setzt ein "0x" vor den String. Die so neu generierte # Hexadezimale Zahl # kann dann wiederum weiterverarbeitet werden #===================================================================== +====== if (length($hex_ip) ne '10') { my @hexadezimale_IP_Adresse_ohne_0x=unpack("H2" x length($hex_ip), pac +k("A*",$hex_ip)); unshift @hexadezimale_IP_Adresse_ohne_0x, "0x"; $hex_ip = join("", @hexadezimale_IP_Adresse_ohne_0x); $hex_ip =~ s/\s+//g; print qq~hex_ip: $hex_ip\n~; } if (substr($hex_ip,0,1) eq "") { $ip = "0.0.0.0"; print "IP: $ip\n"; } else { $hex_ip =~ s/0x//g; $hex1 = (substr $hex_ip,0,2); $hex2 = (substr $hex_ip,2,2); $hex3 = (substr $hex_ip,4,2); $hex4 = (substr $hex_ip,6,2); $oct1 = hex($hex1); $oct2 = hex($hex2); $oct3 = hex($hex3); $oct4 = hex($hex4); $ip = ("$oct1\.$oct2\.$oct3\.$oct4"); } return $ip; }


Comment on Re^2: Cisco SNMP CDP Poll
Download Code
Re^3: Cisco SNMP CDP Poll
by Anonymous Monk on Oct 31, 2010 at 21:56 UTC
    In my case I have found that some devices return strange output, it is in case no mgmt IP is available in sh cdp nei detail (CSS11501), older IOS or different platform.
    DB<69> p $_[0] DB<70> x $_[0] 0 "\c@\c@\c@\c@"
    My dirty hack for that was just check for valid hex-like input
    #if (substr($hex_ip,0,1) eq ""){ if ($hex_ip !~ m/0x.*/){ $ip = "0.0.0.0"; }
      is there a way to modify this script so that it will cycle through a list of choices to use for comminuty string on each device it is polling? Sorry I have no experience at coding, but this script is EXACTLY what I need. I am doing a discovery, I have a list of possible community strings though so i am stuck.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://557156]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-07-29 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (212 votes), past polls