]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/hex2ip.pl
avoid reassigning to temp upon decode_utf8
[infobot.git] / src / Modules / hex2ip.pl
1 #
2 #  hex2ip.pl: Convert hex gateway idents to an IP (eg:ABCDEF12)
3 #     Author: Dan McGrath <djmcgrath@users.sourceforget.net>
4 #  Licensing: Artistic License (as perl itself)
5 #    Version: v0.1
6 #
7 #  Copyright (c) 2007 Dan McGrath
8 #
9
10 package hex2ip;
11
12 use strict;
13
14 sub hex2ip::convert {
15     my $hexstr = shift;
16     my $result;
17
18     &::VERB("hex2ip: Converting Hex address $hexstr to IP");
19
20     if ( $hexstr =~ /^([a-fA-F0-9]{2}){4}$/ ) {
21         my @conv;
22         $hexstr =~ /(..)(..)(..)(..)/;
23
24         push @conv, hex($1);
25         push @conv, hex($2);
26         push @conv, hex($3);
27         push @conv, hex($4);
28
29         $result = uc "$hexstr = " . join( ".", @conv );
30     }
31     else {
32         $result = "Invalid string: $hexstr";
33     }
34
35     return ($result);
36 }
37
38 sub hex2ip::query {
39     &::performStrictReply( &convert(@_) );
40     return;
41 }
42
43 1;
44
45 # vim:ts=4:sw=4:expandtab:tw=80