Perl Monk, Perl Meditation PerlMonks

### Comment on

 Need Help??
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
# kann dann wiederum weiterverarbeitet werden
#=====================================================================
+======

if (length(\$hex_ip) ne '10')
{
+k("A*",\$hex_ip));
\$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;
}

In reply to Re^2: Cisco SNMP CDP Poll by Anonymous Monk
in thread Cisco SNMP CDP Poll by fingers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Please read these before you post! —
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?
• See Writeup Formatting Tips and other pages linked from there for more info.

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-11-23 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (334 votes). Check out past polls.

Notices?